Skip to content

Commit 788f4f5

Browse files
committed
feat: add benchmark for multi_thread
1 parent f3f346a commit 788f4f5

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

benchmarks/multi_thread_comporess.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
require 'benchmark/ips'
2+
$LOAD_PATH.unshift '../lib'
3+
require 'json'
4+
require 'objspace'
5+
require 'zstd-ruby'
6+
require 'thread'
7+
8+
GUESSES = (ENV['GUESSES'] || 1000).to_i
9+
THREADS = (ENV['THREADS'] || 1).to_i
10+
11+
p GUESSES: GUESSES, THREADS: THREADS
12+
13+
sample_file_name = ARGV[0]
14+
json_string = File.read("./samples/#{sample_file_name}")
15+
16+
queue = Queue.new
17+
GUESSES.times { queue << json_string }
18+
THREADS.times { queue << nil }
19+
THREADS.times.map {
20+
Thread.new {
21+
while str = queue.pop
22+
Zstd.compress(str)
23+
end
24+
}
25+
}.each(&:join)

0 commit comments

Comments
 (0)