Skip to content

Commit 06c03e9

Browse files
committed
Add another parser benchmark script
1 parent ffcb7e2 commit 06c03e9

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

bin/benchmark-parse-each.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
require "rbs"
2+
require "benchmark/ips"
3+
require "csv"
4+
5+
if ARGV.empty?
6+
STDERR.puts "Usage: #{$0} FILE..."
7+
STDERR.puts ""
8+
STDERR.puts "Benchmark parsing each file separately and output the result as CSV."
9+
exit 1
10+
end
11+
12+
results = []
13+
14+
total = ARGV.size
15+
ARGV.each_with_index do |file, index|
16+
GC.start
17+
18+
STDERR.puts "#{index}/#{total}\tBenchmarking with #{file}..."
19+
content = File.read(file)
20+
21+
benchmark = Benchmark.ips do |x|
22+
x.report(file) do
23+
RBS::Parser.parse_signature(content)
24+
end
25+
26+
x.quiet = true
27+
end
28+
29+
results << {
30+
file: file,
31+
size: content.bytesize,
32+
ips: benchmark.entries[0].ips,
33+
sd: benchmark.entries[0].ips_sd
34+
}
35+
end
36+
37+
puts CSV.generate {|csv|
38+
csv << ["File", "Size", "IPS", "SD"]
39+
results.each do |result|
40+
csv << [result[:file], result[:size], result[:ips], result[:sd]]
41+
end
42+
}

0 commit comments

Comments
 (0)