Robert Klemme
1/22/2005 2:31:00 PM
"Maarten Boonen" <m44rt3n@yahoo.com> schrieb im Newsbeitrag
news:1106347442.809679@seven.kulnet.kuleuven.ac.be...
> Simon Strandgaard schreef:
>> 5 times is not enough to tell how much time that average is spend in
>> the code.. it usually takes time to do setup/teardown, it can be
>> affected by the operating systems scheduler.
>>
>> The average running time usually becomes visible by running it many
>> times.. over and over.. try with 1000 times.. so that the program spends
>> some seconds
>> in the code.
>
> well, the total testing already takes half an hour, so doing it 1000 times
> isn't really an option. But I'm pretty sure that's not the problem. Some
> example code might clarify:
>
> if I do
>
> [250].each do |sg|
>
> 5.times do
>
> start = Time.now algorithm(sg) puts Time.now - start
> end
>
> end
>
> the times are (in seconds):
>
> 8.853
> 8.602
> 7.33
> 7.281
> 7.32
>
> but if I do
>
> [1,250].each do |sg|
>
> 5.times do
>
> start = Time.now algorithm(sg) puts Time.now - start
> end
>
> end
>
> the times are (for the 250 case):
>
> 2.804
> 4.336
> 3.835
> 4.036
> 3.765
With a straightforward definition of something that simply takes time, I
don't see any significant difference:
>> def algorithm(x) 100000.times {} end
=> nil
>> [250].each do |sg|
?> 5.times do
?> start = Time.now
>> algorithm(sg)
>> puts Time.now - start
>> end
>> end
0.029
0.028
0.028
0.031
0.027
=> [250]
>> [1,250].each do |sg|
?> 5.times do
?> start = Time.now
>> algorithm(sg)
>> puts Time.now - start
>> end
>> end
0.03
0.028
0.029
0.027
0.029
0.029
0.027
0.035
0.03
0.029
=> [1, 250]
I guess this cannot be answered without closer inspection of algorithm.
What exactly does it?
Regards
robert