Skip to content

Instantly share code, notes, and snippets.

@square
Created September 3, 2009 23:51
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 square/180616 to your computer and use it in GitHub Desktop.
Save square/180616 to your computer and use it in GitHub Desktop.
Rehearsal ----------------------------------------------------
normal SHA-1 3.130000 1.040000 4.170000 ( 4.180956)
shell SHA-1 0.010000 0.040000 3.990000 ( 4.042143)
file-based SHA-1 3.010000 0.510000 3.520000 ( 3.534705)
------------------------------------------ total: 11.680000sec
user system total real
normal SHA-1 3.140000 1.040000 4.180000 ( 4.196356)
shell SHA-1 0.010000 0.040000 3.990000 ( 4.007471)
file-based SHA-1 3.010000 0.520000 3.530000 ( 3.544147)
require 'benchmark'
require 'digest/sha1'
name = "big.tar.gz"
Benchmark.bmbm do |x|
x.report("normal SHA-1") {
100.times { File.open(name, 'r') { |file| Digest::SHA1.hexdigest(file.read) } }
}
x.report("shell SHA-1") {
100.times { `openssl sha1 #{name}` }
}
x.report("file-based SHA-1") {
100.times { Digest::SHA1.file(name).hexdigest }
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment