Skip to content

Instantly share code, notes, and snippets.

@pd
Created October 27, 2014 13:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pd/85bf4eb242faa505e170 to your computer and use it in GitHub Desktop.
Save pd/85bf4eb242faa505e170 to your computer and use it in GitHub Desktop.
UUID v5 vs SHA1 hexdigest
require 'json-schema'
require 'digest/sha1'
require 'benchmark'
N = 5000
SCHEMAS = Dir['test/schemas/*.json'].map { |f| File.read(f) }
Benchmark.bmbm do |x|
x.report('v5') do
N.times do
SCHEMAS.each { |schema| JSON::Util::UUID.create_sha1(schema, JSON::Util::UUID::Nil).to_s }
end
end
x.report('SHA1') do
N.times do
SCHEMAS.each { |schema| Digest::SHA1.hexdigest(schema) }
end
end
end
__END__
~/sauce/rb/json-schema [chruby:2.1.1] (master δ) » ruby bench.rb
Rehearsal ----------------------------------------
v5 0.970000 0.000000 0.970000 ( 0.971467)
SHA1 0.150000 0.000000 0.150000 ( 0.144231)
------------------------------- total: 1.120000sec
user system total real
v5 0.970000 0.000000 0.970000 ( 0.970403)
SHA1 0.140000 0.000000 0.140000 ( 0.138115)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment