@@ -8,6 +8,7 @@ module Prism
8
8
class CLI
9
9
def run ( argv )
10
10
case argv . shift
11
+ when "benchmark" then benchmark ( argv )
11
12
when "console" then console
12
13
when "dot" then dot ( argv )
13
14
when "encoding" then encoding ( argv )
@@ -18,10 +19,10 @@ module Prism
18
19
when "parser" then parser ( argv )
19
20
when "ripper" then ripper ( argv )
20
21
when "rubyparser" then rubyparser ( argv )
21
- when "benchmark" then benchmark ( argv )
22
22
else
23
23
puts <<~TXT
24
24
Usage:
25
+ bin/prism benchmark [source_file]
25
26
bin/prism console
26
27
bin/prism dot [source]
27
28
bin/prism encoding [encoding]
@@ -32,7 +33,6 @@ module Prism
32
33
bin/prism parser [source]
33
34
bin/prism ripper [source]
34
35
bin/prism rubyparser [source]
35
- bin/prism benchmark [source_file]
36
36
TXT
37
37
end
38
38
end
@@ -43,6 +43,24 @@ module Prism
43
43
# Commands
44
44
############################################################################
45
45
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
+
46
64
# bin/prism console
47
65
def console
48
66
require "irb"
@@ -248,24 +266,6 @@ module Prism
248
266
pp prism
249
267
end
250
268
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
-
269
269
############################################################################
270
270
# Helpers
271
271
############################################################################
0 commit comments