Created
October 19, 2013 19:17
-
-
Save jgaskins/7060191 to your computer and use it in GitHub Desktop.
Benchmarking hash vs set in Perpetuity::AttributeSet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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