Last active
August 11, 2018 18:38
-
-
Save r00takaspin/204edcd33db01c154036ee3c4f8c8e20 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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