Skip to content

Commit

Permalink
prof
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreMartinon committed Sep 2, 2024
1 parent abb6b37 commit b863ccd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
10 changes: 5 additions & 5 deletions benchmark/benchmark.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,19 @@ function bench(;
end

# +++ put repeat directly in bench()
function bench_average(; repeat = 2, verbose = false, kwargs...)
function bench_average(; repeat = 4, verbose = false, kwargs...)

# execute series of benchmark runs
t_list = []
for i = 1:repeat
t = bench(; verbose = verbose, kwargs...)
append!(t_list, t)
@printf("Run %d / %d: time (s) = %6.2f\n", i, repeat, t)
verbose && @printf("Run %d / %d: time (s) = %6.2f\n", i, repeat, t)
end

# print / return average total time
avg_time = sum(t_list) / length(t_list)
@printf("Average time (s): %6.2f\n", avg_time)
verbose && @printf("Average time (s): %6.2f\n", avg_time)
return avg_time
end

Expand All @@ -140,7 +140,7 @@ function bench_series(; grid_size_list = [250, 500, 1000, 2500, 5000], kwargs...
for grid_size in grid_size_list
t = bench_average(; grid_size = grid_size, kwargs...)
append!(t_list, t)
@printf("Grid size %d: time (s) = %6.2f\n\n", grid_size, t)
@printf("Grid size %d: time (s) = %6.1f\n", grid_size, t)
end
return t_list
#return t_list
end
14 changes: 9 additions & 5 deletions benchmark/prof.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# +++ TODO: make function with bools as args ?
# Profiling
#include("../test/deps.jl")
using CTDirect
using CTBase

Expand Down Expand Up @@ -40,15 +40,19 @@ if precompile
end

if test == :objective
@timev CTDirect.DOCP_objective(CTDirect.DOCP_initial_guess(docp), docp)
println("Timed objective")
#@timev CTDirect.DOCP_objective(CTDirect.DOCP_initial_guess(docp), docp)
@btime CTDirect.DOCP_objective(CTDirect.DOCP_initial_guess(docp), docp)
else
@timev CTDirect.DOCP_constraints!(zeros(docp.dim_NLP_constraints), CTDirect.DOCP_initial_guess(docp), docp)
println("Timed constraints")
#@timev CTDirect.DOCP_constraints!(zeros(docp.dim_NLP_constraints), CTDirect.DOCP_initial_guess(docp), docp)
@btime CTDirect.DOCP_constraints!(zeros(docp.dim_NLP_constraints), CTDirect.DOCP_initial_guess(docp), docp)
end

# full solve
if test_solve
println("Timed solve")
@timev sol = direct_solve(ocp, grid_size = grid_size, display=false)
println("Timed full solve")
#@timev sol = direct_solve(ocp, grid_size = grid_size, display=false)
@btime sol = direct_solve(ocp, grid_size = grid_size, display=false)
end

Expand Down

0 comments on commit b863ccd

Please sign in to comment.