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.
Sven, please give a fully explicit test case. I'm not sure I
understand the ellipses in your account. I tried the following
complete example, broadly similar to what you stated:
<script>
set stopwatch
scalar t_sim1 = 0
scalar B = 100
scalar T = 20
loop for simrun=1..B --quiet
matrix M1 = mnormal(100,100)
matrix M2 = mnormal(100,100)
start = $stopwatch
loop for t=1..T --quiet
matrix Mprod = M1 * M2
end loop
stop = $stopwatch
t_sim1 += stop - start
end loop
print t_sim1
</script>
and it produced no negative results.
Allin.