-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from leifg/benchmarks
add benchmarks
- Loading branch information
Showing
2 changed files
with
120 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,74 @@ | ||
module BenchmarkData | ||
extend self | ||
|
||
def nested_wrapper | ||
:person | ||
end | ||
|
||
def row | ||
{ | ||
first_name: 'Jazmyn', | ||
last_name: 'Willms', | ||
gender: 'female', | ||
phone_number: '485-675-9228', | ||
cell_phone: '1-172-435-9402 x4907', | ||
street_name: 'Becker Inlet', | ||
street_number: '15a', | ||
city: 'Carolynchester', | ||
zip: '38189', | ||
country: 'USA', | ||
} | ||
end | ||
|
||
def row_string_keys | ||
stringify_keys(row) | ||
end | ||
|
||
def row_nested | ||
{ | ||
nested_wrapper => row | ||
} | ||
end | ||
|
||
def row_nested_string_keys | ||
{ | ||
nested_wrapper.to_s => row_string_keys | ||
} | ||
end | ||
|
||
private | ||
def stringify_keys hash | ||
hash.keys.each do |key| | ||
hash[key.to_s] = hash.delete(key) | ||
end | ||
hash | ||
end | ||
|
||
class SimpleMappingSymbol < Morfo::Base | ||
BenchmarkData.row.keys.each do |field| | ||
map field, :"#{field}_mapped" | ||
end | ||
end | ||
|
||
class SimpleMappingString < Morfo::Base | ||
BenchmarkData.row_string_keys.keys.each do |field| | ||
map field, "#{field}_mapped" | ||
end | ||
end | ||
|
||
class NestedMappingSymbol < Morfo::Base | ||
BenchmarkData.row_nested.each do |key, value| | ||
value.keys.each do |field| | ||
map [key, field], :"#{field}_mapped" | ||
end | ||
end | ||
end | ||
|
||
class NestedMappingString < Morfo::Base | ||
BenchmarkData.row_nested_string_keys.each do |key, value| | ||
value.keys.each do |field| | ||
map [key, field], "#{field}_mapped" | ||
end | ||
end | ||
end | ||
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,46 @@ | ||
require 'morfo' | ||
require 'benchmark' | ||
require './benchmarks/data' | ||
|
||
iterations = 100 | ||
batch_size = 10000 | ||
|
||
definitions = [ | ||
{ | ||
label: 'Simple (strings)', | ||
row: BenchmarkData.row_string_keys, | ||
morf_class: BenchmarkData::SimpleMappingString | ||
}, | ||
{ | ||
label: 'Simple (symbols)', | ||
row: BenchmarkData.row, | ||
morf_class: BenchmarkData::SimpleMappingSymbol | ||
}, | ||
{ | ||
label: 'Nested (strings)', | ||
row: BenchmarkData.row_nested_string_keys, | ||
morf_class: BenchmarkData::NestedMappingString | ||
}, | ||
{ | ||
label: 'Nested (symbols)', | ||
row: BenchmarkData.row_nested, | ||
morf_class: BenchmarkData::NestedMappingSymbol | ||
}, | ||
] | ||
|
||
definitions.each do |defintition| | ||
defintition.merge!( | ||
data: Array.new(batch_size){ defintition[:row] } | ||
) | ||
end | ||
|
||
Benchmark.bm(20) do |x| | ||
definitions.each do |defintition| | ||
x.report(defintition[:label]) do | ||
iterations.times do | ||
defintition[:morf_class].morf(defintition[:data]) | ||
end | ||
end | ||
end | ||
end | ||
|