Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3
Bernard Lambeau edited this page Feb 13, 2014
·
8 revisions
There are two kind of benchmarks:
- counting iterations: for a fast single operation
- time for a given
n: for an operation depending on the size of the given input
Here are some ideas for the API:
Perfer.sessiondo |s|
s.iterations'File.stat'doFile.stat(Dir.tmpdir)ends.bench'Array#sort'do |n|
s.description"Sort an Array of n random integers"ary=Array.new(n){rand(n)}s.measuredoary.sortendendend(short and sweet, but against POLS because metadata is evaluated multiple times (and so just reading tags would need one iteration). b has to respond to everything and the notion of "current job" is not a clean approach)
With another level of nesting, to separate benchmark code and metadata:
Perfer.session"Array#sort"do |s|
s.bench"Array#sort"do |b|
b.description"Sort an Array of n random integers"b.bench_codedo |n|
ary=Array.new(n){rand(n)}b.measuredo# should not be b here ideallyary.sortendendendend(looks quite complicated at first sight: 4 levels of nesting)
With the metadata before the #bench block:
Perfer.session"Array#sort"do |s|
s.description"Sort an Array of n random integers"s.tagsArray,:sortings.bench"Array#sort"do |b,n|
ary=Array.new(n){rand(n)}b.measuredoary.sortendendend(fine if not much metadata, job grouping happens by consecutive lines, and no more by nesting)
And the metadata grouped in an instance-eval configuration block:
Perfer.session"Array#sort"do |s|
s.metadatadodescription"Sort an Array of n random integers"tagsArray,:sortingn"the Array size"ends.bench"Array#sort"do |b,n|
ary=Array.new(n){rand(n)}b.measuredo# b could be replaced by s, so b would not be needed anymoreary.sortendendend(good if many items for metadata, again job grouping is less clear)