18 lines
290 B
Crystal
18 lines
290 B
Crystal
def perform_something(&block)
|
|
start = Time.monotonic
|
|
yield
|
|
Time.monotonic - start
|
|
end
|
|
|
|
def perform_benchmark_average(ntimes : Int32, &block)
|
|
i = 1
|
|
sum = Time::Span.zero
|
|
while i <= ntimes
|
|
elapsed_time = perform_something &block
|
|
sum += elapsed_time
|
|
i += 1
|
|
end
|
|
|
|
sum / ntimes
|
|
end
|