Sha256: cb99abbcd5703f981372031dfcacf5a72cc1db7ddf615109a1018b9166388602

Contents?: true

Size: 1.02 KB

Versions: 40

Compression:

Stored size: 1.02 KB

Contents

#!/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) }

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
syntax_tree-6.2.0 bin/bench
syntax_tree-6.1.1 bin/bench
syntax_tree-6.1.0 bin/bench
syntax_tree-6.0.2 bin/bench
syntax_tree-6.0.1 bin/bench
syntax_tree-6.0.0 bin/bench
syntax_tree-5.3.0 bin/bench
syntax_tree-5.2.0 bin/bench
syntax_tree-5.1.0 bin/bench
syntax_tree-5.0.1 bin/bench
syntax_tree-5.0.0 bin/bench
syntax_tree-4.3.0 bin/bench
syntax_tree-4.2.0 bin/bench
syntax_tree-4.1.0 bin/bench
syntax_tree-4.0.2 bin/bench
syntax_tree-4.0.1 bin/bench
syntax_tree-4.0.0 bin/bench
syntax_tree-3.6.3 bin/bench
syntax_tree-3.6.2 bin/bench
syntax_tree-3.6.1 bin/bench