Skip to content

Instantly share code, notes, and snippets.

@michaeldwan
Created March 18, 2011 20:51
Show Gist options
  • Save michaeldwan/876813 to your computer and use it in GitHub Desktop.
Save michaeldwan/876813 to your computer and use it in GitHub Desktop.

Revisions

  1. michaeldwan created this gist Mar 18, 2011.
    21 changes: 21 additions & 0 deletions profile.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    // Pass a function to profile and optionally the number of times to run
    function profile(test, times) {
    var start = new Date().getTime();
    if (times === undefined) {
    times = 100;
    }

    for (i = 0; i < times; ++i) {
    test();
    };
    var end = new Date().getTime();
    var time = end - start;
    print('took: ' + time);
    }

    // Example
    profile(function () {
    1 + 2;
    }, 10000)