Skip to content

Instantly share code, notes, and snippets.

@ianks
Created May 2, 2015 18:46
Show Gist options
  • Save ianks/15362d1a28e24d57fe41 to your computer and use it in GitHub Desktop.
Save ianks/15362d1a28e24d57fe41 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'benchmark'
class StateClass
def initialize(value, mark)
@value, @mark = value, mark
end
end
class StateStruct < Struct.new(:value, :mark); end
count = 10_000_000
Benchmark.bmbm do |x|
x.report('StateClass') { count.times { StateClass.new('test', true).freeze } }
x.report('StateStruct') { count.times { StateStruct.new('test', true).freeze } }
x.report('StateArray') { count.times { ['test', true].freeze } }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment