Skip to content

Commit

Permalink
Add mixed pattern matching bench
Browse files Browse the repository at this point in the history
  • Loading branch information
palkan committed Nov 18, 2019
1 parent 523479c commit 4bca11b
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions benchmarks/pattern_matching_mixed.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# frozen_string_literal: true

# Hack to use bundled benchmark-driver
module Bundler
def self.with_unbundled_env(&block); yield; end
end

require "benchmark_driver"

require "ruby-next/language"

# from https://www.ruby-lang.org/en/news/2019/10/22/ruby-2-7-0-preview2-released/
source = %q{
def alice(data)
case data
in {name: "Alice", children: [{name: "Bob", age: age}]}
p "Bob age is #{age}"
in _
"No Alice"
end
end
}

next_source = RubyNext::Language.transform(source).gsub! "def alice(", "def alice_next("

Benchmark.driver do |x|
x.prelude %Q{
require 'json'
#{source}
#{next_source}
data = {
name: 'Alice',
children: [{
name: 'Bob',
age: 30
}]
}
}
x.report "baseline", %{ alice data }
x.report "transpiled", %{ alice_next data }
end

0 comments on commit 4bca11b

Please sign in to comment.