Refactoring: Fix benchmark code smell (#7211)

Merge pull request 7211
This commit is contained in:
Vitor Oliveira 2018-09-02 15:01:11 -03:00 committed by jekyllbot
parent a693153755
commit 397d289cd2
1 changed files with 14 additions and 19 deletions

View File

@ -90,26 +90,21 @@ end
Correctness.new(site_docs, "redirect_from".freeze).assert! Correctness.new(site_docs, "redirect_from".freeze).assert!
Correctness.new(site_docs, "title".freeze).assert! Correctness.new(site_docs, "title".freeze).assert!
# First, test with a property only a handful of documents have. def test_property(property, meta_key)
Benchmark.ips do |x| Benchmark.ips do |x|
x.config(time: 10, warmup: 5) x.config(time: 10, warmup: 5)
x.report('sort_by_property_directly with sparse property') do x.report("sort_by_property_directly with #{property} property") do
sort_by_property_directly(site_docs, "redirect_from".freeze) 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 end
x.report('schwartzian_transform with sparse property') do
schwartzian_transform(site_docs, "redirect_from".freeze)
end
x.compare!
end 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. # Next, test with a property they all have.
Benchmark.ips do |x| test_property('non-sparse', 'title')
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