Last active
March 6, 2020 14:32
-
-
Save DCarper/0f1e3b100fbb26ade655e646c4caed88 to your computer and use it in GitHub Desktop.
benchmark.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* benchmark.js | |
* | |
*/ | |
define ( | |
[ ], | |
function() { | |
function benchMark(name, func) { | |
var benchMarkedFunction = function() { | |
var startTime = Date.now(); | |
log.audit("Benchmark", '---Beginning ' + name + '---'); | |
log.audit("Benchmark", name + " - parameters: " + arguments); | |
var result = func.apply(this, arguments); | |
var timeElapsed = Math.round(((Date.now() - startTime) / 60 / 60) * 10000) / 10000; | |
log.audit("Benchmark", '---Ending ' + name + ' ' + timeElapsed + ' seconds elapsed' + '---'); | |
return result; | |
}; | |
return benchMarkedFunction; | |
} | |
return { | |
benchMark: benchMark | |
} | |
} | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* myModule.js | |
* | |
*/ | |
define ( | |
[ 'path/to/benchmark' ], | |
function(myLogger) { | |
var helperFunc = myLogger.benchMark( | |
"MyModule.helperFunc", | |
function() { | |
} | |
) | |
function getInputData() { } | |
function map() { helperFunc() } | |
function summarize() { } | |
return { | |
getInputData: myLogger.benchMark("MyModule.getInputData", getInputData) | |
map: myLogger.benchMark("MyModule.map", map) | |
summarize: myLogger.benchMark("MyModule.summarize", summarize) | |
} | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment