Skip to content

Instantly share code, notes, and snippets.

@torbjon
Created December 7, 2012 00:26
Show Gist options
  • Select an option

  • Save torbjon/4229684 to your computer and use it in GitHub Desktop.

Select an option

Save torbjon/4229684 to your computer and use it in GitHub Desktop.
require 'digest/md5'
require 'benchmark'
parts = []
body = ['Hello World']
Benchmark.bm do |x|
x.report('each') do
body.each { |part| parts << part }
Digest::MD5.hexdigest(parts.join)
end
x.report('map') do
parts = body.map { |part| part }
Digest::MD5.hexdigest(parts.join)
end
end
# user system total real
# each 0.000000 0.000000 0.000000 ( 0.000078)
# map 0.000000 0.000000 0.000000 ( 0.000012)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment