Benchmark
The Benchmark module allows code execution to be timed and the results tabulated. Benchmark is easier to use if you include it in your top-level environment.
The most useful method of Benchmark is Benchmark.bm(label_width = 0, *labels) { |report| ...}. The bm method passes a report object to the block. Inside the block, you call report(caption) on that object one or more times, passing a block each time. Ruby will execute each block and emit a table with an entry for each block listing the time spent by the CPU executing code (user time), the CPU time spent by the system during the block (system time), the total of those two (total), and the amount of clock time that passed during the block.
This example compares the costs of four ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access