Skip to content

Instantly share code, notes, and snippets.

@kschlarman
kschlarman / benchmark.md
Created September 11, 2012 02:11
The Benchmark Module

##Benchmark The benchmark module provides an easy way to time how long your Ruby code takes to run. In this example, I will use the bm method to generate sequential reports with labels.

This bit of code compares two different ways to concatenate strings. It times how long it takes to concatenate a period at the end of a string of 10,000 a's, one million times in a row. The label for the each test is passed into the report method.

require 'benchmark'

Benchmark.bm do |x|
 # Test for concatenation with +=
@kschlarman
kschlarman / gist:3628654
Created September 5, 2012 00:54
Ruby Bytecode
puts RubyVM::InstructionSequence.compile('puts "hello bytecode"').disassemble