Skip to content
Permalink
Browse files

Refactoring: Fix benchmark code smell (#7211)

Merge pull request 7211
  • Loading branch information...
vbrazo authored and jekyllbot committed Sep 2, 2018
1 parent a693153 commit 397d289cd2146542440fa38e004fd4df88110d7f
Showing with 14 additions and 19 deletions.
  1. +14 −19 benchmark/schwartzian_transform.rb
@@ -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.
You can’t perform that action at this time.