Skip to content

Instantly share code, notes, and snippets.

@r00takaspin
Last active August 11, 2018 18:38
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 r00takaspin/204edcd33db01c154036ee3c4f8c8e20 to your computer and use it in GitHub Desktop.
Save r00takaspin/204edcd33db01c154036ee3c4f8c8e20 to your computer and use it in GitHub Desktop.
require 'benchmark'
require 'digest'
require 'etc'
THREAD_NUMBER = Etc.nprocessors
def count_md5(id)
tmp = id.to_s
1_000_000.times { tmp = Digest::MD5.hexdigest(tmp) }
tmp
end
Benchmark.bm do |x|
x.report do
threads = []
THREAD_NUMBER.times { threads << Thread.new { count_md5(Thread.current.object_id) } }
threads.each(&:join)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment