Skip to content

Commit

Permalink
Refactoring: Fix benchmark code smell (#7211)
Browse files Browse the repository at this point in the history
Merge pull request 7211
  • Loading branch information
vbrazo authored and jekyllbot committed Sep 2, 2018
1 parent a693153 commit 397d289
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions benchmark/schwartzian_transform.rb
Expand Up @@ -90,26 +90,21 @@ def assert!
Correctness.new(site_docs, "redirect_from".freeze).assert!
Correctness.new(site_docs, "title".freeze).assert!

# First, test with a property only a handful of documents have.
Benchmark.ips do |x|
x.config(time: 10, warmup: 5)
x.report('sort_by_property_directly with sparse property') do
sort_by_property_directly(site_docs, "redirect_from".freeze)
end
x.report('schwartzian_transform with sparse property') do
schwartzian_transform(site_docs, "redirect_from".freeze)
def test_property(property, meta_key)
Benchmark.ips do |x|
x.config(time: 10, warmup: 5)
x.report("sort_by_property_directly with #{property} property") do
sort_by_property_directly(site_docs, meta_key)
end
x.report("schwartzian_transform with #{property} property") do
schwartzian_transform(site_docs, meta_key)
end
x.compare!
end
x.compare!
end

# First, test with a property only a handful of documents have.
test_property('sparse', 'redirect_from')

# Next, test with a property they all have.
Benchmark.ips do |x|
x.config(time: 10, warmup: 5)
x.report('sort_by_property_directly with non-sparse property') do
sort_by_property_directly(site_docs, "title".freeze)
end
x.report('schwartzian_transform with non-sparse property') do
schwartzian_transform(site_docs, "title".freeze)
end
x.compare!
end
test_property('non-sparse', 'title')

0 comments on commit 397d289

Please sign in to comment.