Chuck-Remess-Mac-Pro:perf cremes$ ruby uuid_bench.rb
Rehearsal -------------------------------------------------------------------------
class allocation: 59.914000 0.000000 59.914000 ( 59.914000)
uuid generation: 0.020000 0.000000 0.020000 ( 0.020000)
--------------------------------------------------------------- total: 59.934000sec
user system total real
class allocation: 59.310000 0.000000 59.310000 ( 59.310000)
uuid generation: 0.013000 0.000000 0.013000 ( 0.013000)
Chuck-Remess-Mac-Pro:perf cremes$ ruby -v
jruby 1.7.0.dev (ruby-1.8.7-p352) (2011-12-19 f404f75) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_29) [darwin-x86_64-java]
Chuck-Remess-Mac-Pro:perf cremes$ rvm system
Chuck-Remess-Mac-Pro:perf cremes$ ruby uuid_bench.rb
Rehearsal -------------------------------------------------------------------------
class allocation: 0.003916 0.000361 0.004277 ( 0.004240)
uuid generation: 0.005223 0.000498 0.005721 ( 0.005720)
---------------------------------------------------------------- total: 0.009998sec
user system total real
class allocation: 0.003570 0.000199 0.003769 ( 0.003759)
uuid generation: 0.003729 0.000237 0.003966 ( 0.003967)
Chuck-Remess-Mac-Pro:perf cremes$ ruby -v
rubinius 2.0.0dev (1.8.7 964a1a2b yyyy-mm-dd JI) [x86_64-apple-darwin10.8.0]
# Test the performance of creating UUID instances and generating
# UUID values.
#
require 'rubygems'
require 'benchmark'
require 'uuid'
UUID.state_file = false
class Bar1
def alloc_it
UUID.new
end
end # Bar1
class Bar2
def initialize
@uuid = UUID.new
end
def alloc_it
@uuid.generate
end
end
@bar1 = Bar1.new
@bar2 = Bar2.new
Iterations = 100
Benchmark.bmbm("Compare UUID allocation and generation".size) do |x|
x.report("class allocation:") do
Iterations.times { @bar1.alloc_it }
end
x.report("uuid generation:") do
Iterations.times { @bar2.alloc_it }
end
end