Page 1 of 1

### Timer in NEURON ( similar to tic() and toc() in Matlab)

Posted: Tue Mar 04, 2014 3:38 am
I wonder is there any function in NEURON that similar to tic() and toc() in Matlab?
I would like to use it to record processing time of my simulation.
After going through Documentation and threads here, I couldn't find it.

### Re: Timer in NEURON ( similar to tic() and toc() in Matlab)

Posted: Wed Mar 05, 2014 3:21 am
I found one variable that could show the simulation time, that is "realtime".
It did not work similarly like tic() and toc() function in MATLAB that could be use as a timer anywhere in your code, however. But I could get along with it for now.

### Re: Timer in NEURON ( similar to tic() and toc() in Matlab)

Posted: Wed Mar 05, 2014 11:27 am
You want startsw(); see documentation in the Programmer's Reference.

Code: Select all

``````t0 = startsw()
. . . model setup code . . .
t1 = startsw()
run() // executes a simulation
t2 = startsw()
print "model setup time ", t1-t0, " run time ", t2-t1, " total ", t2-t0``````

### Re: Timer in NEURON ( similar to tic() and toc() in Matlab)

Posted: Wed Mar 05, 2014 9:43 pm
Thank you!

### Re: Timer in NEURON ( similar to tic() and toc() in Matlab)

Posted: Thu Mar 06, 2014 12:01 am
startsw isn't a very "obvious" name for such a function, but if you dig into stdrun.hoc you'll find that realtime is calculated from values returned by calls to startsw.

Time for two big hints.

1. NEURON's standard run system is implemented almost entirely in hoc, and this hoc code is contained in the hoc library, which is in nrn/lib/hoc. There's lots of interesting and reusable code in the hoc library, and it's a good idea to browse through it.

2. If you come across a particular variable or class or procedure or function whose name is not defined in the Programmer's Reference, this means it is not built into hoc. Instead, it will either be defined in the hoc library, which is in nrn/lib/hoc, or by code contained in a user-written hoc or NMODL file.

"Oh, but RealTime actually is in the Programmer's Reference."

True, because RealTime is a label that appears on a button in the RunControl panel, and the Programmer's Reference contains a description of what this label means. However, never forget that hoc is case-sensitive. "RealTime" is not the name of any hoc variable. Neither is the variable called "realtime"--that variable is defined in stdrun.hoc and is not one of hoc's built-in variables.