Skip to content

Instantly share code, notes, and snippets.

@jgaskins
Created October 19, 2013 19:17
Show Gist options
  • Save jgaskins/7060191 to your computer and use it in GitHub Desktop.
Save jgaskins/7060191 to your computer and use it in GitHub Desktop.
Benchmarking hash vs set in Perpetuity::AttributeSet
require_relative '../lib/perpetuity/attribute_set.rb'
require_relative '../lib/perpetuity/attribute.rb'
require 'benchmark/ips'
include Perpetuity
attributes = AttributeSet.new
names = %w(foo bar baz quux abc def ghi)
names.each do |name|
attributes << Attribute.new(name)
end
Benchmark.ips do |x|
x.report('AttributeSet iteration') { attributes.each {} }
x.report('AttributeSet indexing') { attributes[names.sample] }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment