Skip to content

Instantly share code, notes, and snippets.

@ptdorf
Forked from pd/uuid-vs-sha1.rb
Created July 16, 2023 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ptdorf/0ed71aaf7607b0d2911d0e1e625deba1 to your computer and use it in GitHub Desktop.
Save ptdorf/0ed71aaf7607b0d2911d0e1e625deba1 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