Navigation Menu

Skip to content

eligrey/timer.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

API

new Timer()
Instantiates a new timer.

Instance methods

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.

FAQ

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.

Tracking image

About

High-precision JavaScript timer

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published