Commit in hps-java/src/main/java/org/lcsim/hps/util on MAIN | |||
TimerDriver.java | +38 | added 1.1 |
timer driver, for fun
diff -N TimerDriver.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ TimerDriver.java 8 Aug 2012 01:02:21 -0000 1.1 @@ -0,0 +1,38 @@
+package org.lcsim.hps.util; + +import org.lcsim.event.EventHeader; +import org.lcsim.util.Driver; + +/** + * Lightweight timer driver. Add one copy of this driver to measure time per event; add multiple copies to measure time between two points in the execute list. + * @author Sho Uemura <[log in to unmask]> + * @version $Id: TimerDriver.java,v 1.1 2012/08/08 01:02:21 meeg Exp $ + */ +public class TimerDriver extends Driver { + + private static long time = Long.MIN_VALUE; + private long timeElapsed; + private int count = 0; + private String name = "unnamed"; + private boolean verbose = false; + + public void setName(String name) { + this.name = name; + } + + @Override + public void process(EventHeader event) { + long oldTime = time; + time = System.nanoTime(); + if (oldTime != Long.MIN_VALUE) { + long dt = time - oldTime; + timeElapsed += dt; + count++; + if (verbose) { + System.out.format("Timer %s: dt %f, timeElapsed %d, count %d, mean time %f ms\n", name, dt / 1.0e6, timeElapsed, count, (timeElapsed / 1.0e6) / count); + } else { + System.out.format("Timer %s: dt %f, mean time %f ms\n", name, dt / 1.0e6, (timeElapsed / 1.0e6) / count); + } + } + } +}
Use REPLY-ALL to reply to list
To unsubscribe from the LCD-CVS list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=LCD-CVS&A=1