Forum: Ruby check performance with Benchmark

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
73700e119917433681f2e8f3e4369f74?d=identicon&s=25 Li CN (alex-osu3)
on 2007-01-19 16:31
(Received via mailing list)
Hi all,

I know I can use this format to check the performance
of my sctipt:

result= Benchmark.measure{##script included here##}

But this code  will look ugly if the script spans many
lines.I wonder 1) if there is a better means and 2)
what if I want to check the same script for 10000
times.


Thanks,

Li
97550977337c9f0a0e1a9553e55bfaa0?d=identicon&s=25 Jan Svitok (Guest)
on 2007-01-19 16:31
(Received via mailing list)
On 1/13/07, chen li <chen_li3@yahoo.com> wrote:
> times.
Hi,

1. you can put the script in a method/function and call that.
2. use 10000.times { } ;-)
  either result = Benchmark.measure { 10000.times { script }}
  or result = 1..10000.map { Benchmark.measure { script }}
73700e119917433681f2e8f3e4369f74?d=identicon&s=25 Li CN (alex-osu3)
on 2007-09-25 22:35
(Received via mailing list)
--- Jan Svitok <jan.svitok@gmail.com> wrote:
> Hi,
>
> 1. you can put the script in a method/function and
> call that.
> 2. use 10000.times { } ;-)
>   either result = Benchmark.measure { 10000.times {
> script }}
>   or result = 1..10000.map { Benchmark.measure {
> script }}


Jan,

Thank you for your cute idea and my script looks
better now.

Li
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (Guest)
on 2007-09-25 22:37
(Received via mailing list)
On 13.01.2007 05:03, chen li wrote:
> I know I can use this format to check the performance
> of my sctipt:
>
> result= Benchmark.measure{##script included here##}
>
> But this code  will look ugly if the script spans many
> lines.I wonder 1) if there is a better means and 2)
> what if I want to check the same script for 10000
> times.

Just look at the various pieces of sample code using benchmark that are
posted here (comp.lang.ruby / ruby-talk).

Kind regards

  robert
This topic is locked and can not be replied to.