generate uuid

N

Newb Newb

How Can I generate uuid ? any references or Ideas could You people
suggest.I have not even heard about it?
 
A

ara.t.howard

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/
 
I

Ilan Berci

Newb said:
How Can I generate uuid ? any references or Ideas could You people
suggest.I have not even heard about it?


sudo gem install guid


irb(main):001:0> require 'guid'
=> true
irb(main):002:0> Guid.new
=> b93e5a88-acf7-be64-af0b-6de00bd83fd3
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top