Skip to content

Commit 1128917

Browse files
committed
chore: add benchmark for streaming
1 parent 7c732a8 commit 1128917

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
require 'benchmark/ips'
2+
3+
$LOAD_PATH.unshift '../lib'
4+
5+
require 'json'
6+
require 'objspace'
7+
require 'zstd-ruby'
8+
9+
p "#{ObjectSpace.memsize_of_all/1000} #{ObjectSpace.count_objects} #{`ps -o rss= -p #{Process.pid}`.to_i}"
10+
11+
sample_file_name = ARGV[0]
12+
13+
json_string = IO.read("./samples/#{sample_file_name}")
14+
15+
i = 0
16+
while true do
17+
stream = Zstd::StreamingCompress.new
18+
stream << json_string
19+
res = stream.flush
20+
res << stream.finish
21+
if ((i % 1000) == 0 )
22+
GC.start
23+
puts "count:#{i}\truby_memory:#{ObjectSpace.memsize_of_all/1000}\tobject_count:#{ObjectSpace.count_objects}\trss:#{`ps -o rss= -p #{Process.pid}`.to_i}"
24+
end
25+
i += 1
26+
end
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
require 'benchmark/ips'
2+
3+
$LOAD_PATH.unshift '../lib'
4+
5+
require 'json'
6+
require 'zstd-ruby'
7+
require 'objspace'
8+
9+
p "#{ObjectSpace.memsize_of_all/1000} #{ObjectSpace.count_objects} #{`ps -o rss= -p #{Process.pid}`.to_i}"
10+
11+
sample_file_name = ARGV[0]
12+
13+
cstr = IO.read("./results/#{sample_file_name}.zstd")
14+
i = 0
15+
while true do
16+
stream = Zstd::StreamingDecompress.new
17+
result = ''
18+
result << stream.decompress(cstr[0, 10])
19+
result << stream.decompress(cstr[10..-1])
20+
21+
if ((i % 1000) == 0 )
22+
puts "count:#{i}\truby_memory:#{ObjectSpace.memsize_of_all/1000}\tobject_count:#{ObjectSpace.count_objects}\trss:#{`ps -o rss= -p #{Process.pid}`.to_i}"
23+
end
24+
i += 1
25+
end

0 commit comments

Comments
 (0)