Last active
August 24, 2025 06:31
-
-
Save kigster/0edbc05439e509ff164671ba7afec759 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 'etc' | |
| require 'parallel' | |
| input = ('a'..'z').map { |letter| [letter, letter] }.to_h | |
| index = 0 | |
| N = 5_000_000 | |
| cpu_count = Etc.nprocessors.to_i | |
| cpu_array = (0...cpu_count).to_a | |
| work = ->(count) { count.times { input.map { |key, value| [key.to_sym, value] }.to_h } } | |
| results = Parallel.map(cpu_array, in_processes: cpu_count) do |cpu| | |
| Benchmark.bm do |x| | |
| x.report("cpu #{'%2d' % cpu}") { work[N] } | |
| end | |
| end | |
| # puts results |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment