Created
November 15, 2013 21:31
-
-
Save teeparham/7491991 to your computer and use it in GitHub Desktop.
benchmark simple ruby string to int hashing
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' | |
strs = 1000.times.map{(0...32).map{(65 + rand(26)).chr}.join} | |
Benchmark.bm(6) do |x| | |
x.report('sum') { 100.times{strs.each &:sum} } | |
x.report('digest') { 100.times{strs.each{|s| Digest::MD5.hexdigest(s).to_i(16) }}} | |
end | |
# user system total real | |
# sum 0.000000 0.000000 0.000000 ( 0.007893) | |
# digest 0.290000 0.030000 0.320000 ( 0.309167) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment