From: "ara.t.howard" Date: 2008-09-02T09:15:09+09:00 Subject: Re: generate uuid On Sep 1, 2008, at 5:38 PM, Ryan Davis wrote: > > On Sep 1, 2008, at 14:48 , James Gray wrote: > >> My favorite trick is: >> >> uuid = `uuidgen`.strip >> >> It has always been fast enough for my needs. > > that's nice. 10k real uuids in 1 minute is perfectly acceptable for > almost all cases. thanks. > > % ./blah.rb 10000 > # of iterations = 10000 > user system total real > null_time 0.000000 0.000000 0.000000 ( 0.001486) > ezra 0.200000 0.000000 0.200000 ( 0.201678) > uuidgen 1.160000 12.630000 58.190000 ( 56.684045) > > ---- > > puts "# of iterations = #{max}" > Benchmark::bm(20) do |x| > x.report("null_time") do > for i in 0..max do > # do nothing > end > end > > x.report("ezra") do > for i in 0..max do > fast_token > end > end > > x.report("uuidgen") do > for i in 0..max do > `uuidgen`.strip > end > end > end > > cfp:~ > cat a.rb require 'open-uri' uri = 'http://s3.amazonaws.com/drawohara.com.ruby/uuid.rb' eval open(uri).read a = Time.now.to_f ( n = 1000 ).times{ uuid = UUID.string } b = Time.now.to_f elapsed = b - a puts "uuid/min : #{ n / elapsed * 60 }" cfp:~ > ruby a.rb uuid/min : 113947.784509223 it's kinda a POS, but with the addition of macaddr and a few other tidbits (state using AR for instance) it's pretty dang good : 10 times faster and pure ruby. a @ http://codeforpeople.com/ -- we can deny everything, except that we have the possibility of being better. simply reflect on that. h.h. the 14th dalai lama