Skip to content

Commit

Permalink
Run profiling under perf evals times
Browse files Browse the repository at this point in the history
I don't know how accurate perf is for functions that take nanoseconds. My understanding is that running a function `evals` times should take at least a couple microseconds so I think this should improve profiling accuracy with neglibile extra time taken.
  • Loading branch information
Zentrik committed Jan 19, 2024
1 parent 1ee189b commit cfa2cef
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/src/manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ You can pass the following keyword arguments to `@benchmark`, `@benchmarkable`,
- `gcsample`: If `true`, run `gc()` before each sample. Defaults to `BenchmarkTools.DEFAULT_PARAMETERS.gcsample = false`.
- `time_tolerance`: The noise tolerance for the benchmark's time estimate, as a percentage. This is utilized after benchmark execution, when analyzing results. Defaults to `BenchmarkTools.DEFAULT_PARAMETERS.time_tolerance = 0.05`.
- `memory_tolerance`: The noise tolerance for the benchmark's memory estimate, as a percentage. This is utilized after benchmark execution, when analyzing results. Defaults to `BenchmarkTools.DEFAULT_PARAMETERS.memory_tolerance = 0.01`.
- `enable_linux_perf`: If `true`, profile using perf once. Defaults to `BenchmarkTools.DEFAULT_PARAMETERS.enable_linux_perf = false`.
- `enable_linux_perf`: If `true`, profile using perf `evals` times. Defaults to `BenchmarkTools.DEFAULT_PARAMETERS.enable_linux_perf = false`.

To change the default values of the above fields, one can mutate the fields of `BenchmarkTools.DEFAULT_PARAMETERS`, for example:

Expand Down
5 changes: 4 additions & 1 deletion src/execution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -604,8 +604,11 @@ function generate_benchmark_definition(
$(setup)
try
$LinuxPerf.enable!(__linux_perf_bench)
# We'll just run it one time.
# We'll run it evals times.
__return_val_2 = $(invocation)
for __iter in 2:__evals
$(invocation)
end
$LinuxPerf.disable!(__linux_perf_bench)
# trick the compiler not to eliminate the code
if rand() < 0
Expand Down

0 comments on commit cfa2cef

Please sign in to comment.