Google es tu amigo:
http://www.ruby-doc.org/stdlib/libdoc/benchmark/rdoc/classes/Benchmark.html
Seria algo como
require "benchmark"
Benchmark.bm do |b|
b.report("implementacion 1:") { 10_000.times {
method_with_implementation_1() } }
b.report("implementacion 2:") { 10_000.times {
method_with_implementation_2() } }
# ...
end
Al correrlo te va a dar el time de cada implementacion, en 10000 iteraciones.
-foca
On Thu, Jun 4, 2009 at 2:41 PM, Fabricio <[email protected]> wrote:
>
> def time_elapsed()
> time_in_milis = Time.new
> ret_value = yield if block_given?
> time_in_milis = Time.new - time_in_milis
> puts "Executed in #{time_in_milis} ms"
> return ret_value
> end
>
> time_elapsed { c(cad) }
>
>
>
> Saludos.
> Fabricio Tuosto
>
>
> 2009/6/4 Leandro Marcucci <[email protected]>
>>
>> 2009/6/4 p8queen <[email protected]>:
>> > hola amigos,
>> > como mido el tiempo que tarda un funcion ?
>> > ej:
>> >
>> > def c(cad)
>> > return cad.upcase
>> > end
>> >
>> > en realidad la funcion es mas complejas y tengo diferentes maneras de
>> > resolver un problema, por eso quiero medir el tiempo.
>> >
>> > gracias
>> >
>> > --
>> > Gustavo C
>> > _______________________________________________
>> > Ruby mailing list
>> > [email protected]
>> > http://lista.rubyargentina.com.ar/listinfo.cgi/ruby-rubyargentina.com.ar
>> >
>>
>>
>> def c(cad)
>> start_time = Time.now
>> a = cad.upcase
>> end_time = Time.now
>> puts/logger/loquesea "Duracion: #{end_time - start_time}"
>> return a
>> end
>>
>> ??
>>
>> Saludos.
>> --
>> Leandro Marcucci.
>> http://twitter.com/leanucci
>> _______________________________________________
>> Ruby mailing list
>> [email protected]
>> http://lista.rubyargentina.com.ar/listinfo.cgi/ruby-rubyargentina.com.ar
>
>
> _______________________________________________
> Ruby mailing list
> [email protected]
> http://lista.rubyargentina.com.ar/listinfo.cgi/ruby-rubyargentina.com.ar
>
>
_______________________________________________
Ruby mailing list
[email protected]
http://lista.rubyargentina.com.ar/listinfo.cgi/ruby-rubyargentina.com.ar