Created
September 28, 2012 17:46
-
-
Save jonleighton/3801227 to your computer and use it in GitHub Desktop.
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 'benchmark/ips' | |
| class A | |
| def initialize | |
| @attributes = { :foo => 1 } | |
| end | |
| def foo | |
| @attributes[:foo] | |
| end | |
| end | |
| class B | |
| def initialize | |
| @attributes = { 'foo' => 1 } | |
| end | |
| def foo | |
| @attributes['foo'] | |
| end | |
| end | |
| a = A.new | |
| b = B.new | |
| Benchmark.ips do |r| | |
| r.report('symbol') { a.foo } | |
| r.report('string') { b.foo } | |
| end |
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
| $ ruby benchmark_access.rb | |
| Calculating ------------------------------------- | |
| symbol 49716 i/100ms | |
| string 45447 i/100ms | |
| ------------------------------------------------- | |
| symbol 2495270.4 (±4.5%) i/s - 12478716 in 5.014637s | |
| string 1645124.6 (±8.2%) i/s - 8180460 in 5.012095s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment