Skip to content

Commit 40059d3

Browse files
committed
Benchmark script style
1 parent b2b6e2b commit 40059d3

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

bin/prism

+20-20
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module Prism
88
class CLI
99
def run(argv)
1010
case argv.shift
11+
when "benchmark" then benchmark(argv)
1112
when "console" then console
1213
when "dot" then dot(argv)
1314
when "encoding" then encoding(argv)
@@ -18,10 +19,10 @@ module Prism
1819
when "parser" then parser(argv)
1920
when "ripper" then ripper(argv)
2021
when "rubyparser" then rubyparser(argv)
21-
when "benchmark" then benchmark(argv)
2222
else
2323
puts <<~TXT
2424
Usage:
25+
bin/prism benchmark [source_file]
2526
bin/prism console
2627
bin/prism dot [source]
2728
bin/prism encoding [encoding]
@@ -32,7 +33,6 @@ module Prism
3233
bin/prism parser [source]
3334
bin/prism ripper [source]
3435
bin/prism rubyparser [source]
35-
bin/prism benchmark [source_file]
3636
TXT
3737
end
3838
end
@@ -43,6 +43,24 @@ module Prism
4343
# Commands
4444
############################################################################
4545

46+
# bin/prism benchmark [source_file]
47+
def benchmark(argv)
48+
require "benchmark/ips"
49+
require "parser/current"
50+
require "ruby_parser"
51+
52+
filepath = argv.fetch(0) { File.expand_path("../lib/prism/node.rb", __dir__) }
53+
54+
Benchmark.ips do |x|
55+
x.report("prism") { Prism.parse_file(filepath) }
56+
x.report("parser") { Parser::CurrentRuby.parse_file(filepath) }
57+
x.report("Prism::Translation::Parser") { Prism::Translation::Parser.parse_file(filepath) }
58+
x.report("ruby_parser") { RubyParser.new.parse(File.read(filepath), filepath) }
59+
x.report("Prism::Translation::RubyParser") { Prism::Translation::RubyParser.parse_file(filepath) }
60+
x.compare!
61+
end
62+
end
63+
4664
# bin/prism console
4765
def console
4866
require "irb"
@@ -248,24 +266,6 @@ module Prism
248266
pp prism
249267
end
250268

251-
# bin/prism benchmark [source_file]
252-
def benchmark(argv)
253-
require "benchmark/ips"
254-
require "parser/current"
255-
require "ruby_parser"
256-
257-
filepath = argv.fetch(0) { File.expand_path("../lib/prism/translation/parser/compiler.rb", __dir__) }
258-
259-
Benchmark.ips do |x|
260-
x.report("Parser::CurrentRuby") { Parser::CurrentRuby.parse_file(filepath) }
261-
x.report("Parser::Prism") { Prism.parse_file(filepath) }
262-
x.report("Prism::Translation::Parser") { Prism::Translation::Parser.parse_file(filepath) }
263-
x.report("RubyParser") { RubyParser.new.parse(File.read(filepath), filepath) }
264-
x.report("Prism::Translation::RubyParser") { Prism::Translation::RubyParser.parse_file(filepath) }
265-
x.compare!
266-
end
267-
end
268-
269269
############################################################################
270270
# Helpers
271271
############################################################################

0 commit comments

Comments
 (0)