Skip to content

Commit

Permalink
Benchmark script style
Browse files Browse the repository at this point in the history
  • Loading branch information
kddnewton committed Feb 16, 2024
1 parent b2b6e2b commit 40059d3
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions bin/prism
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Prism
class CLI
def run(argv)
case argv.shift
when "benchmark" then benchmark(argv)
when "console" then console
when "dot" then dot(argv)
when "encoding" then encoding(argv)
Expand All @@ -18,10 +19,10 @@ module Prism
when "parser" then parser(argv)
when "ripper" then ripper(argv)
when "rubyparser" then rubyparser(argv)
when "benchmark" then benchmark(argv)
else
puts <<~TXT
Usage:
bin/prism benchmark [source_file]
bin/prism console
bin/prism dot [source]
bin/prism encoding [encoding]
Expand All @@ -32,7 +33,6 @@ module Prism
bin/prism parser [source]
bin/prism ripper [source]
bin/prism rubyparser [source]
bin/prism benchmark [source_file]
TXT
end
end
Expand All @@ -43,6 +43,24 @@ module Prism
# Commands
############################################################################

# bin/prism benchmark [source_file]
def benchmark(argv)
require "benchmark/ips"
require "parser/current"
require "ruby_parser"

filepath = argv.fetch(0) { File.expand_path("../lib/prism/node.rb", __dir__) }

Benchmark.ips do |x|
x.report("prism") { Prism.parse_file(filepath) }
x.report("parser") { Parser::CurrentRuby.parse_file(filepath) }
x.report("Prism::Translation::Parser") { Prism::Translation::Parser.parse_file(filepath) }
x.report("ruby_parser") { RubyParser.new.parse(File.read(filepath), filepath) }
x.report("Prism::Translation::RubyParser") { Prism::Translation::RubyParser.parse_file(filepath) }
x.compare!
end
end

# bin/prism console
def console
require "irb"
Expand Down Expand Up @@ -248,24 +266,6 @@ module Prism
pp prism
end

# bin/prism benchmark [source_file]
def benchmark(argv)
require "benchmark/ips"
require "parser/current"
require "ruby_parser"

filepath = argv.fetch(0) { File.expand_path("../lib/prism/translation/parser/compiler.rb", __dir__) }

Benchmark.ips do |x|
x.report("Parser::CurrentRuby") { Parser::CurrentRuby.parse_file(filepath) }
x.report("Parser::Prism") { Prism.parse_file(filepath) }
x.report("Prism::Translation::Parser") { Prism::Translation::Parser.parse_file(filepath) }
x.report("RubyParser") { RubyParser.new.parse(File.read(filepath), filepath) }
x.report("Prism::Translation::RubyParser") { Prism::Translation::RubyParser.parse_file(filepath) }
x.compare!
end
end

############################################################################
# Helpers
############################################################################
Expand Down

0 comments on commit 40059d3

Please sign in to comment.