Sampling and measurement of execution cycles
To measure a single execution cycle:
result = Diagnostics::Sample.() do
some_method(...)
end
result.time_milliseconds
# => 11.1
To measure many execution cycles (i.e. iterations):
result = Diagnostics::Sample.(1000) do
some_method(...)
end
# Total elapsed time across all cycles
result.time_milliseconds
# => 11111.11
# Average elapsed time across all cycles
result.mean_cycle_time_milliseconds
# => 11.1
# Cycles per second
result.cycle_frequency
# => 111.1
A number of warmup cycles may be specified:
Diagnostics::Sample.(1000, warmup_cycles: 10) do
some_method(...)
end
The garbage collector by default is disabled during the measurement. It can be enabled optionally:
Diagnostics::Sample.(1000, gc: true) do
some_method(...)
end
The diagnostics-sample
library is released under the MIT License.