#!/usr/bin/env ruby require 'benchmark' require 'ruby_parser' $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__)) require 'parser/all' def measure(what) rp_failures = 0 p_failures = 0 Benchmark.bm(10) do |x| x.report "ruby_parser" do what.each do |file, src| begin Ruby18Parser.new.parse(src) rescue => e puts file puts "RP: #{e.class}: #{e.message}" rp_failures += 1 end end end x.report "parser" do what.each do |file, src| begin Parser::Ruby20.parse(src, file) rescue Parser::SyntaxError p_failures += 1 rescue => e puts file puts "P: #{e.class}: #{e.message}" puts e.backtrace p_failures += 1 end end end end puts puts "Failures: RP: #{rp_failures} P: #{p_failures}" end files = Hash[ARGV.map { |f| [f, File.read(f)] }] measure(files)