Last active
December 16, 2015 21:39
-
-
Save bl4de/5501104 to your computer and use it in GitHub Desktop.
Inspired by Paul Irish's some short introduction into Performance Memory and Timing API in Google Chrome - http://www.youtube.com/watch?feature=player_profilepage&v=MllBwuHbWMY - ( Performance Timing is also available in Firefox) I created a simple object Forebone.Performance in Forebone.js library. First of all, I will create methods to wrap al…
This file contains 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
// for now supports both only in Chrome | |
if (typeof performance.memory == "object" && | |
typeof performance.timing == "object") { | |
/** | |
* Forebone.Performance - wrapper for performance.timing | |
* and performance.memory | |
*/ | |
Forebone.Performance = { | |
// memory functions | |
getHeapSize : function() { | |
return performance.memory.totalJSHeapSize; | |
}, | |
getHeapSizeLimit : function() { | |
return performance.memory.jsHeapSizeLimit; | |
}, | |
getHeapSizeUsed : function() { | |
return performance.memory.usedJSHeapSize; | |
}, | |
getHeapSizeStat : function() { | |
return (( this.getHeapSizeUsed() * 100 ) / this.getHeapSizeLimit()).toFixed(2); | |
}, | |
// timing functions | |
getTiming : function() { | |
var start = this.getNavigationStart(); | |
var str = "Performance timing flow: "; | |
str += "\ndomLoading: " + (this.getDomLoading()-start) + " ms."; | |
return str; | |
}, | |
getNavigationStart : function() { | |
return performance.timing.navigationStart; | |
}, | |
getDomLoading : function() { | |
return performance.timing.domLoading; | |
}, | |
getDomComplete : function() { | |
return performance.timing.domComplete; | |
} | |
}; | |
} else { | |
Forebone.Performance = {}; | |
} |
This file contains 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
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Forebone.Window example</title> | |
<script src="../lib/forebone.js"></script> | |
</head> | |
<body> | |
<script> | |
// sample usage | |
var Debug = Forebone.Performance; | |
console.log( Debug.getHeapSizeUsage() ); | |
console.log( Debug.getTiming() ); | |
/* output in Google Chrome console: | |
JavaScript memory heap usage: 1.26% ForebonePerformance.html:12 | |
Performance timing flow: | |
domLoading: 8 ms. ForebonePerformance.html:13 | |
*/ | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment