MonoForge

3n0 / mootime

mootime

Public

Extends Function Native with a couple of simple methods for logging execution time of functions.

3 filesupdated Jun 19, 2026

README

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.