On Thu, 30 Apr 2009, Allin Cottrell wrote:
On Thu, 30 Apr 2009, Sven Schreiber wrote:
> I'm getting negative numbers from using $stopwatch differences,
> could there be some sort of underflow problem?
>
> What I do is a typical simulation exercise:
>
> set stopwatch
> t_sim1 = 0
> loop for simrun=1..replications --quiet
> <create random numbers>
> loop for t=1..T --quiet
> <do stuff with random numbers>
> start = $stopwatch
> <do more stuff>
> stop = $stopwatch
> <do more stuff>
> t_sim1 += stop-start
> end loop # t
> end loop # simrun
> print t_sim1
>
> And t_sim1 is reproducibly negative.
Ah, I tried this again using an exact copy of your script with
<stuff> filled in, and I did indeed get negative values of t_sim1.
I was bothered at first, but then realized that's perfectly OK.
I'd failed to notice the problem in your script.
As per the manual, $stopwatch gives you the time _elapsed_ since
"set stopwatch", or since the previous call to $stopwatch. Your
calls
start = $stopwatch
...
stop = $stopwatch
...
t_sim1 += stop-start
seem to be assuming that $stopwatch gives you the current time,
not the elapsed time: you want t_sim1 += $stopwatch.
Allin.