| Reference | Downloads | Github

Check Timing: Can I insert inner clocks to output the timing of Routines?

Description of the problem:
Is there a way to insert through the builder inline code before and after a routine to measure its timing?

I attempted to define a variable timer = util.clock() at the begin of the routine and to insert another clock at the end of the routine. Unfortunately at the end of the experiment (run online) it writes the variable but they are blank?

trialtimer = util.Clock();
psychoJS.experiment.addData(‘endtrial’, trialtimer)

I used the Auto -> JS.

Thanks a lot for your help.

trialtimer = new util.Clock(); // define a beginning of experiment

// then in routine
starttrial = globalClock.getTime();
endtrial = globalClock.getTime();
timediff = globalClock.getTime() - starttrial;

psychoJS.experiment.addData(‘endtrial’, endtrial);