Timing a simulation


#1

Hi all,

I’m trying to run a nengo simulator and time the actual amount of time it takes to run the simulation. If I try to use time.time() before and after the sim.run(x) call, it will output an incorrect time. For instance if I do sim.run(2), it will say it took 20 seconds to run, but the expected value is about 5 seconds and I hand timed it to also be about 5 seconds.

Alternatively, if I use Spyder and set breakpoints before and after I use time.time(), then I will get the correct timing. So I’m guessing there is some sort of precompile before I can run the simulation and that’s causing the problem with timing the simulation.

Does anyone know how to properly time a nengo simulation and have it output the correct time?

Below is my code:

with nengo.Simulator(model) as sim:
    start = time.time()
    sim.run(2)
    end = time.time()
    print(end - start)

#2

That code should give the correct time information, and there isn’t really any way for Nengo to change that timing. That is, if you do

start = time.time()
<some code>
print(time.time() - start)

then it really doesn’t matter what <some code> is, the timing information there is just a product of the time module and the python interpreter. So if I had to guess there’s something funky with your python environment that is messing up your time information. As a test, you could check if this also gives you strange output:

start = time.time()
time.sleep(5.0)
print(time.time() - start)

#3

Hi @drasmuss, thank you for responding.

I tried the test with time.sleep(5.0) and it did print out 5 seconds.

For now I guess I’ll continue with the breakpoint method until I can find a better solution.