Skip to content

Commit

Permalink
feat: add benchmark for multi_thread
Browse files Browse the repository at this point in the history
  • Loading branch information
SpringMT committed Apr 11, 2024
1 parent f3f346a commit 788f4f5
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions benchmarks/multi_thread_comporess.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require 'benchmark/ips'
$LOAD_PATH.unshift '../lib'
require 'json'
require 'objspace'
require 'zstd-ruby'
require 'thread'

GUESSES = (ENV['GUESSES'] || 1000).to_i
THREADS = (ENV['THREADS'] || 1).to_i

p GUESSES: GUESSES, THREADS: THREADS

sample_file_name = ARGV[0]
json_string = File.read("./samples/#{sample_file_name}")

queue = Queue.new
GUESSES.times { queue << json_string }
THREADS.times { queue << nil }
THREADS.times.map {
Thread.new {
while str = queue.pop
Zstd.compress(str)
end
}
}.each(&:join)

0 comments on commit 788f4f5

Please sign in to comment.