-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |