Skip to content

Commit

Permalink
Benchmark macro in its own folder; not use global; fix a plural error
Browse files Browse the repository at this point in the history
  • Loading branch information
bennettm committed Apr 9, 2024
1 parent b8d2a9e commit c845648
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 69 deletions.
1 change: 0 additions & 1 deletion src/GenX.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ function include_all_in_folder(folder)
for file in files
if endswith(file, ".jl")
include(joinpath(root, file))
println("include " * joinpath(root,file))
end
end
end
Expand Down
61 changes: 0 additions & 61 deletions src/additional_tools/benchmark_macro.jl

This file was deleted.

7 changes: 4 additions & 3 deletions src/benchmark/benchmark_macro.jl
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
@doc draw"""
@benchmarked <expr to benchmark> [setup=<setup expr>] [other keyword parameters...]
Run benchmarked on a given expression.
Run @benchmarked on a given expression.
This macro is a customization of BenchmarkTools' `@benchmark`.
`@benchmark` only provides benchmark results.
With this customization, we can benchmark a function that has a return value.
Customization uses internals from BenchmarkTools.
Updates to this macro is needed when internals get changed from BenchmarkTools.
#Example
This macro is compatible with BenchmarkTools v1.3.2, so this version is pinned in Project.toml.
"""

using BenchmarkTools
Expand All @@ -35,7 +36,7 @@ macro benchmarked(args...)
" (",
$trialallocs,
" allocation",
$trialallocs == 1 ? "" : "s",
$trialallocs == 1 || $trialallocs == 0 ? "" : "s",
": ",
$BenchmarkTools.prettymemory($BenchmarkTools.memory($trialmin)),
")",
Expand Down
8 changes: 4 additions & 4 deletions src/case_runners/case_runner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ case - folder for the case
function run_genx_case!(case::AbstractString, optimizer::Any=HiGHS.Optimizer)
genx_settings = get_settings_path(case, "genx_settings.yml") # Settings YAML file path
writeoutput_settings = get_settings_path(case, "output_settings.yml") # Write-output settings YAML file path
global mysetup = configure_settings(genx_settings, writeoutput_settings) # mysetup dictionary stores settings and GenX-specific parameters
mysetup = configure_settings(genx_settings, writeoutput_settings) # mysetup dictionary stores settings and GenX-specific parameters

if mysetup["MultiStage"] == 0
run_genx_case_simple!(case, mysetup, optimizer)
Expand Down Expand Up @@ -50,18 +50,18 @@ function run_genx_case_simple!(case::AbstractString, mysetup::Dict, optimizer::A

### Configure solver
println("Configuring Solver")
global OPTIMIZER = configure_solver(settings_path, optimizer)
OPTIMIZER = configure_solver(settings_path, optimizer)

#### Running a case

### Load inputs
println("Loading Inputs")
global myinputs = load_inputs(mysetup, case)
myinputs = load_inputs(mysetup, case)

println("Generating the Optimization Model")
## Benchmark enabled
if mysetup["Benchmark"] == 1
EP, bm_results = @benchmarked generate_model(mysetup, myinputs, OPTIMIZER) seconds=30 samples=1000 evals=1
EP, bm_results = @benchmarked generate_model($mysetup, $myinputs, $OPTIMIZER) seconds=30 samples=1000 evals=1
println("Benchmark results for generate_model: ")
BenchmarkTools.display(bm_results)
else
Expand Down

0 comments on commit c845648

Please sign in to comment.