// 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)