timer.js is a JavaScript library that implements a constructor for creating high-resolution (up to µs) timers.
Please note that the microseconds()
method is only accurate to the µs in Google Chrome
7+ with the launch option, --enable-benchmarking
.
new Timer()
- Instantiates a new timer.
timer.start()
- Starts the timer.
timer.stop()
- Stops the timer.
timer.seconds()
- Returns the amount of time, in seconds, that have passed after starting the timer, and up to stopping the timer if it has been stopped.
timer.milliseconds()
- Same as
timer.seconds()
, but returns milliseconds. timer.microseconds()
- Same as
timer.seconds()
, but returns microseconds. timer.profile(test, iterations)
- Profiles running a function the amount of iterations specified with the timer.
Will you add support for web worker threads so I profile multiple tests concurrently?
I don't know how practical running two profiling tests at once is, but if demand is high enough, I'll make a web worker integration script for this library. The API would mostly be the same, except that profiled code will have to be strings instead of functions, and there would be callback parameters for all of the methods.