Skip to content

Commit 3872428

Browse files
committed
Add benchmarking/profiling scripts
1 parent e7bcf64 commit 3872428

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

bin/benchmark-parse.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
require "rbs"
2+
require "benchmark/ips"
3+
require "csv"
4+
require "pathname"
5+
6+
files = {}
7+
ARGV.each do |file|
8+
content = File.read(file)
9+
files[file] = RBS::Buffer.new(content: content, name: Pathname(file))
10+
end
11+
12+
puts "Benchmarking parsing #{files.size} files..."
13+
14+
result = Benchmark.ips do |x|
15+
x.report("parsing") do
16+
files.each do |file, content|
17+
RBS::Parser.parse_signature(content)
18+
end
19+
end
20+
21+
x.quiet = true
22+
end
23+
24+
entry = result.entries[0]
25+
puts "✅ #{"%0.3f" % entry.ips} i/s (±#{"%0.3f" % entry.error_percentage}%)"

bin/profile-parse.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
require 'rbs'
2+
require "optparse"
3+
4+
wait = false
5+
duration = 3
6+
7+
args = ARGV.dup
8+
9+
OptionParser.new do |opts|
10+
opts.banner = "Usage: profile-parse.rb [options] FILE"
11+
12+
opts.on("--wait", "Wait for enter before starting") do
13+
wait = true
14+
end
15+
opts.on("--duration=NUMBER", "Repeat parsing for <NUMBER> seconds") do |number|
16+
duration = number.to_i
17+
end
18+
end.parse!(args)
19+
20+
if wait
21+
puts "⏯️ Waiting for enter to continue at #{Process.pid}..."
22+
STDIN.gets
23+
end
24+
25+
file = args.shift or raise "No file path is given"
26+
sig = File.read(file)
27+
28+
puts "Parsing #{file} -- #{sig.bytesize} bytes"
29+
30+
started_at = Time.now
31+
count = 0
32+
33+
loop do
34+
count += 1
35+
RBS::Parser.parse_signature(sig)
36+
break if (Time.now - started_at) > duration
37+
end
38+
39+
puts "✅ Done #{count} loop(s)"

0 commit comments

Comments
 (0)