[ANN] Bench 1.0.0 released

J

Jan Friedrich

Bench version 1.0.0 released!
http://bench.rubyforge.org

== DESCRIPTION

Do you remeber how to use the benchmark library from the Ruby standard
lib? I don't.

Now you need not to remember, there is Bench: A DSL around the benchmark
lib of the Ruby
standard lib with the goal to make benchmarking as easy as possible.

== SYNOPSIS

Adapted example of the benchmark documentation from the pickaxe version 2
page 657

require 'bench'

string = 'Stormy Weather'
m = string.method:)length)

benchmark 'code' do
m.call
end

benchmark 'send' do
string.send:)length)
end

benchmark 'eval' do
eval "string.length"
end

run 10_000

== CREDITS

Copyright 2008 by Jan Friedrich ([email protected])

== LICENSE

Ruby's license.
 
R

Ryan Davis

Do you remeber how to use the benchmark library from the Ruby standard
lib? I don't.

Now you need not to remember, there is Bench: A DSL around the
benchmark
lib of the Ruby standard lib with the goal to make benchmarking as
easy as possible.

If I don't remember how to use the benchmark library, why would I
remember how to use your DSL?

That is what ri is for. `ri Benchmark` obviates the need for Bench.
 
J

Jan Friedrich

Ryan said:
If I don't remember how to use the benchmark library, why would I
remember how to use your DSL?
Because it has only 2 commands: benchmark and run. ;)
That is what ri is for. `ri Benchmark` obviates the need for Bench.
Maybe, but with bench it's a pleasure to doing benchmarks interactive
with irb:
user system total real
simple 0.000000 0.000000 0.000000 ( 0.003960)
freezed 0.010000 0.000000 0.010000 ( 0.004870)
user system total real
simple 0.010000 0.000000 0.010000 ( 0.003969)
freezed 0.000000 0.000000 0.000000 ( 0.004624)
?> run 10000
user system total real
simple 0.060000 0.000000 0.060000 ( 0.058049)
freezed 0.060000 0.000000 0.060000 ( 0.058636)
user system total real
simple 0.500000 0.000000 0.500000 ( 0.502427)
freezed 0.540000 0.000000 0.540000 ( 0.533421)
?> RE = /ll/
user system total real
simple 0.000000 0.000000 0.000000 ( 0.000031)
freezed 0.000000 0.000000 0.000000 ( 0.000469)
constant 0.000000 0.000000 0.000000 ( 0.000031)

But It's certainly a question of taste. :)

Regards,
Jan Friedrich
 
T

Trans

Bench version 1.0.0 released!http://bench.rubyforge.org

=3D=3D DESCRIPTION

Do you remeber how to use the benchmark library from the Ruby standard
lib? I don't.

Now you need not to remember, there is Bench: A DSL around the benchmark
lib of the Ruby
standard lib with the goal to make benchmarking as easy as possible.

=3D=3D SYNOPSIS

Adapted example of the benchmark documentation from the pickaxe version 2
page 657

=A0 require 'bench'

=A0 string =3D 'Stormy Weather'
=A0 m =3D string.method:)length)

=A0 benchmark 'code' do
=A0 =A0 m.call
=A0 end

=A0 benchmark 'send' do
=A0 =A0 string.send:)length)
=A0 end

=A0 benchmark 'eval' do
=A0 =A0 eval "string.length"
=A0 end

=A0 run 10_000

What is the underlying translation of benchmark? I.e. the original
Benchmark library has a few different methods, which did you use? I
like the simplicity of your DSL. In the long run it might be nice to
see this advance beyond a dependency on the original benchmark
library.

T.
 
J

Jan Friedrich

Trans said:
What is the underlying translation of benchmark? I.e. the original
Benchmark library has a few different methods, which did you use? I like
the simplicity of your DSL. In the long run it might be nice to see this
advance beyond a dependency on the original benchmark library.
Let's look at the code:

def run count=1
size = Bench.queue.inject(0) {|max, bm| size = bm.name.size; size >
max ? size : max}
Benchmark.bm(size) do |x|
Bench.queue.each do |bm|
x.report(bm.name) { count.times {bm.proc.call} }
end
end
end


Two methods of the original benchmark are called:
* Benchmark.bm with an automatic calculated label_width (I don't want to
think about that).
* Benchmark::Report#report

You can call run as often as you want and do GC.start or whatever before,
so you can simulate the Benchmark.bmbm method. That is enough for my
needs.

Maybe there is a better approach? Feel free to contribute:
http://gitorious.org/projects/bench :)

Regards
Jan Friedrich
 
J

Joel VanderWerf

Jan said:
x.report(bm.name) { count.times {bm.proc.call} }

Suggestion:

x.report(bm.name) { count.times(&bm.proc) }

This will run faster, and more importantly less of the reported time
will be due to framework overhead.
 
J

Jan Friedrich

Joel VanderWerf said:
x.report(bm.name) { count.times(&bm.proc) }

This will run faster, and more importantly less of the reported time
will be due to framework overhead.
Thanks a lot. :)

Regards
Jan Friedrich
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top