chocolate_bar2410/lunarbench
v1.0.0 ·
a benching marking library based off deno bench
lunarbench
lunarbench is a benchmarking package based off of deno bench.
lunar bench not only will test benchmarks but will also have the option to print it out as a nice table or as a CSV.
set bench cases, and compare results. bench cases can be grouped together.
methods:
- lunarbench.bench() - creates a new benchcase
- lunarbench.print_result() - prints the rule
- lunarbench.evaluate_as_csv() - returns the result as a CSV
- lunarbench.set_printoptions() - configures the print output
A bench context is passed into every benchcase on evaluation. You can use the bench context's start and stop methods to declaratively mark the start and stop times. Otherwise lunarbench will handle it for you.
example: for loop benchmarking
local lunarbench = require("@lunarbench")
lunarbench.bench("for loop", function(bench_context)
local tab = table.create(1e7, 1)
bench_context.start()
for i = 1, #tab do
end
end, { baseline = true })
lunarbench.bench("for each", function(bench_context)
local tab = table.create(1e7, 1)
bench_context.start()
for i, v in tab do
end
end)
lunarbench.bench("ipairs", function(bench_context)
local tab = table.create(1e7, 1)
bench_context.start()
for i, v in ipairs(tab) do
end
end)
lunarbench.set_printoptions({ column_seperator = " " })
lunarbench.print_result()
the result
benchmark time/iter (avg) iter/s (min .. max) p75 p99 p995
--------- --------------- ------ ------------------ ------ ------ ------
for loop 20.1μs 49.7 (19.6μs .. 20.8μs) 20.2μs 20.8μs 20.8μs
for each 27.6μs 36.3 (25.9μs .. 32.2μs) 27.8μs 31.9μs 32.0μs
ipairs 27.9μs 35.8 (26.1μs .. 32.1μs) 28.4μs 31.2μs 31.7μs
summary
for loop
0.73x faster than for each
0.72x faster than ipairs