This repository has been archived by the owner on Oct 6, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
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
14 changed files
with
263 additions
and
1 deletion.
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
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
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,23 @@ | ||
#!/usr/bin/env ruby | ||
# encoding: utf-8 | ||
|
||
require_relative 'utils/setup.rb' | ||
|
||
user_model = Class.new(OpenStruct) | ||
|
||
mapper = build_mapper do | ||
attribute :name | ||
attribute :email | ||
model user_model | ||
end | ||
|
||
tuples = create_tuple_collection(100) do | ||
{ | ||
name: Faker::Name.name, | ||
email: Faker::Internet.email | ||
} | ||
end | ||
|
||
run('model_instantiation') do |x| | ||
x.report { mapper.call(tuples) } | ||
end |
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,20 @@ | ||
#!/usr/bin/env ruby | ||
# encoding: utf-8 | ||
|
||
require_relative 'utils/setup.rb' | ||
|
||
mapper = build_mapper do | ||
attribute :name | ||
attribute :email | ||
end | ||
|
||
tuples = create_tuple_collection(100) do | ||
{ | ||
name: Faker::Name.name, | ||
email: Faker::Internet.email | ||
} | ||
end | ||
|
||
run('noop') do |x| | ||
x.report { mapper.call(tuples) } | ||
end |
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,22 @@ | ||
#!/usr/bin/env ruby | ||
# encoding: utf-8 | ||
|
||
require_relative 'utils/setup.rb' | ||
|
||
mapper = build_mapper do | ||
reject_keys true | ||
attribute :name | ||
attribute :email | ||
end | ||
|
||
tuples = create_tuple_collection(100) do | ||
{ | ||
'name' => Faker::Name.name, | ||
'email' => Faker::Internet.email, | ||
Faker::Lorem.word => Faker::Lorem.word | ||
} | ||
end | ||
|
||
run('reject_keys') do |x| | ||
x.report { mapper.call(tuples) } | ||
end |
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,20 @@ | ||
#!/usr/bin/env ruby | ||
# encoding: utf-8 | ||
|
||
require_relative 'utils/setup.rb' | ||
|
||
mapper = build_mapper do | ||
attribute :name, from: 'name' | ||
attribute :email, from: 'email' | ||
end | ||
|
||
tuples = create_tuple_collection(100) do | ||
{ | ||
'name' => Faker::Name.name, | ||
'email' => Faker::Internet.email | ||
} | ||
end | ||
|
||
run('rename_keys') do |x| | ||
x.report { mapper.call(tuples) } | ||
end |
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,10 @@ | ||
=> benchmark: model_instantiation | ||
=> host: andy-HP-ENVY-TS-15-Notebook-PC | ||
=> revision: f75efff2d51b0c2ad2760db93fb423052fa48d63 | ||
=> repo_state: clean | ||
|
||
Calculating ------------------------------------- | ||
164.000 i/100ms | ||
------------------------------------------------- | ||
1.575k (±10.3%) i/s - 7.872k | ||
******************************************************************************** |
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,10 @@ | ||
=> benchmark: noop | ||
=> host: andy-HP-ENVY-TS-15-Notebook-PC | ||
=> revision: f75efff2d51b0c2ad2760db93fb423052fa48d63 | ||
=> repo_state: clean | ||
|
||
Calculating ------------------------------------- | ||
88.492k i/100ms | ||
------------------------------------------------- | ||
1.519M (± 3.9%) i/s - 7.610M | ||
******************************************************************************** |
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,10 @@ | ||
=> benchmark: reject_keys | ||
=> host: andy-HP-ENVY-TS-15-Notebook-PC | ||
=> revision: f75efff2d51b0c2ad2760db93fb423052fa48d63 | ||
=> repo_state: clean | ||
|
||
Calculating ------------------------------------- | ||
610.000 i/100ms | ||
------------------------------------------------- | ||
6.245k (± 4.9%) i/s - 31.720k | ||
******************************************************************************** |
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,10 @@ | ||
=> benchmark: rename_keys | ||
=> host: andy-HP-ENVY-TS-15-Notebook-PC | ||
=> revision: f75efff2d51b0c2ad2760db93fb423052fa48d63 | ||
=> repo_state: clean | ||
|
||
Calculating ------------------------------------- | ||
819.000 i/100ms | ||
------------------------------------------------- | ||
8.999k (± 6.7%) i/s - 45.045k | ||
******************************************************************************** |
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,10 @@ | ||
=> benchmark: symbolize_keys | ||
=> host: andy-HP-ENVY-TS-15-Notebook-PC | ||
=> revision: f75efff2d51b0c2ad2760db93fb423052fa48d63 | ||
=> repo_state: clean | ||
|
||
Calculating ------------------------------------- | ||
889.000 i/100ms | ||
------------------------------------------------- | ||
8.880k (± 4.9%) i/s - 44.450k | ||
******************************************************************************** |
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,21 @@ | ||
#!/usr/bin/env ruby | ||
# encoding: utf-8 | ||
|
||
require_relative 'utils/setup.rb' | ||
|
||
mapper = build_mapper do | ||
symbolize_keys true | ||
attribute :name | ||
attribute :email | ||
end | ||
|
||
tuples = create_tuple_collection(100) do | ||
{ | ||
'name' => Faker::Name.name, | ||
'email' => Faker::Internet.email | ||
} | ||
end | ||
|
||
run('symbolize_keys') do |x| | ||
x.report { mapper.call(tuples) } | ||
end |
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,84 @@ | ||
require 'bundler' | ||
Bundler.require | ||
|
||
require 'socket' | ||
require 'ostruct' | ||
require 'benchmark/ips' | ||
require 'faker' | ||
require 'rom-mapper' | ||
|
||
begin | ||
require 'byebug' | ||
rescue LoadError | ||
end | ||
|
||
# Enable and start GC before each job run. Disable GC afterwards. | ||
# | ||
# Inspired by https://www.omniref.com/ruby/2.2.1/symbols/Benchmark/bm?#annotation=4095926&line=182 | ||
class GCSuite | ||
def warming(*) | ||
run_gc | ||
end | ||
|
||
def running(*) | ||
run_gc | ||
end | ||
|
||
def warmup_stats(*) | ||
end | ||
|
||
def add_report(*) | ||
end | ||
|
||
private | ||
|
||
def run_gc | ||
GC.enable | ||
GC.start | ||
GC.disable | ||
end | ||
end | ||
|
||
def hr | ||
puts "*" * 80 | ||
end | ||
|
||
def run(title, &block) | ||
benchmark(title, &block) | ||
end | ||
|
||
def git_state | ||
state = `git status -uno --porcelain`.split($/).reject do |line| | ||
line.split(' ').last.start_with?('benchmarks/results/') | ||
end | ||
|
||
state.empty? ? 'clean' : "#{$/} => #{state.join("#{$/} => ")}" | ||
end | ||
|
||
def benchmark(title) | ||
puts "=> benchmark: #{title}" | ||
puts "=> host: #{Socket.gethostname}" | ||
puts "=> revision: #{`git rev-parse HEAD`}" | ||
puts "=> repo_state: #{git_state}" | ||
puts $/ | ||
Benchmark.ips do |x| | ||
x.config(suite: GCSuite.new) | ||
yield x | ||
x.compare! | ||
end | ||
hr | ||
end | ||
|
||
def create_mapper(&block) | ||
Class.new(ROM::Mapper).tap do |mapper_klass| | ||
mapper_klass.instance_eval(&block) | ||
end | ||
end | ||
|
||
def build_mapper(&block) | ||
create_mapper(&block).build | ||
end | ||
|
||
def create_tuple_collection(size, &block) | ||
size.times.map { block.call } | ||
end |
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,11 @@ | ||
#!/usr/bin/env ruby | ||
# encoding: utf-8 | ||
|
||
BENCHMARK_DIR = File.expand_path('../../benchmarks', __FILE__) | ||
RESULTS_DIR = File.expand_path('../../benchmarks/results', __FILE__) | ||
BENCHMARKS = Dir[File.join(BENCHMARK_DIR, '*')].select {|f| File.file?(f) }.sort | ||
RESULTS = BENCHMARKS.map { |bm| File.join(RESULTS_DIR, File.basename(bm)) } | ||
|
||
BENCHMARKS.zip(RESULTS).each do |benchmark, result| | ||
system("#{benchmark} | tee #{result}") | ||
end |