Created
August 19, 2011 00:02
-
-
Save heycarsten/1155608 to your computer and use it in GitHub Desktop.
Benchmarking generating fairly unique tokens quickly without external dependencies
This file contains 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' | |
Benchmark.bmbm do |x| | |
x.report('printf') do | |
for i in 1..1_000_000 | |
3.times.map { '%06x' % rand(0x100000) }.join | |
end | |
end | |
x.report('to_s') do | |
for i in 1..1_000_000 | |
3.times.map { rand(0x100000).to_s(36) }.join | |
end | |
end | |
end | |
# Rehearsal ------------------------------------------ | |
# printf 8.580000 0.020000 8.600000 ( 8.597337) | |
# to_s 3.010000 0.000000 3.010000 ( 3.019717) | |
# -------------------------------- total: 11.610000sec | |
# | |
# user system total real | |
# printf 8.560000 0.020000 8.580000 ( 8.584776) | |
# to_s 3.040000 0.000000 3.040000 ( 3.039551) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment