-
Notifications
You must be signed in to change notification settings - Fork 0
Extends Function Native with a couple of simple methods for logging execution time of functions.
License
3n/mootime
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
mootime for MooTools 1.2 Version 0.1 Author: Ian Collins (3n) DESCRIPTION mootime extends the Function Native with a couple of simple methods for logging the execution time of the given function. 'time' will immediately run the function and console.log its execution time upon finishing. 'avg_time' will store all the running times of a given function until it stops being called for 1 second, at which point it will console.log the average time across all the executions. SYNTAX my_function.time([message[, bind[, args]]]) my_function.avg_time([message[, bind[, args]]]) ARGUMENTS message : (string, optional) The message (usually name of the function) to prepend bind : (object, optional) the value of the 'this' keyword inside my_function when executed args : (array if multiple, optional) the arguments to pass to my_function when executed RETURNS Both methods return the return of the function they are attached to. EXAMPLES // compare $ and $$ execution times $.time('$', window, 'derp') $$.time('$$', window, '#derp') // get average run-time of a function 'awesome' inside a tight loop (100).times(function(x) { awesome.avg_time('awesome', this, ['some', 'args', 'for', 'awesome']) }) // anonymous function example function derp(){ var asdf = "asdf" var blah = "blah"; (function(){ $(asdf).addEvent('click', do_something) $(blah).addEvent('click', do_stuff) }).time('adding events'); } TODO - Make a version of .time that returns a modified version of the function rather than calling it. Useful for functions that shouldn't be called immediately, but rather passed for execution later.
About
Extends Function Native with a couple of simple methods for logging execution time of functions.
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published