-
-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathbench
executable file
·42 lines (33 loc) · 1.02 KB
/
bench
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env ruby
# frozen_string_literal: true
require "bundler/inline"
gemfile do
source "https://rubygems.org"
gem "benchmark-ips"
gem "parser", require: "parser/current"
gem "ruby_parser"
end
$:.unshift(File.expand_path("../lib", __dir__))
require "syntax_tree"
def compare(filepath)
prefix = "#{File.expand_path("..", __dir__)}/"
puts "=== #{filepath.delete_prefix(prefix)} ==="
source = File.read(filepath)
Benchmark.ips do |x|
x.report("syntax_tree") { SyntaxTree.parse(source) }
x.report("parser") { Parser::CurrentRuby.parse(source) }
x.report("ruby_parser") { RubyParser.new.parse(source) }
x.compare!
end
end
filepaths = ARGV
# If the user didn't supply any files to parse to benchmark, then we're going to
# default to parsing this file and the main syntax_tree file (a small and large
# file).
if filepaths.empty?
filepaths = [
File.expand_path("bench", __dir__),
File.expand_path("../lib/syntax_tree/node.rb", __dir__)
]
end
filepaths.each { |filepath| compare(filepath) }