News for hackers. Stuff that matters.
Re:The Difference Between Ruby Symbols and Strings by BFalkner on Monday January 19, 2009 @08:10PM (#441173)
The second benchmark isn't particularly fair. We're supposed to be testing == speed, not object creation. It should be something like:

test_str1, test_str2 = "test", "test" str = Benchmark.measure do 10_000_000.times do test_str1 == test_str2 end end.total

testsym1, testsym2 = :test, :test sym = Benchmark.measure do 10_000_000.times do testsym1 == testsym2 end end.total

Of course you might not need to create two strings, and definitely not two symbols. Somebody want to run this? (I'm on a communal computer with no Ruby.)

There are no comments on this comment yet.