Created
August 5, 2014 13:56
-
-
Save shubhadeep/df877a3e07bd2ccc1039 to your computer and use it in GitHub Desktop.
Comparison of binding SAPUI5 button actions as in-line functions (closures) vs. binding the same instance (by function name). Compare the memory heap profile to see the difference in both cases.
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
/** | |
* Comparison of binding button actions as inline functions (closures) | |
* profile to see the difference in both cases. | |
* vs. binding the same instance (by function name). Compare the memory heap | |
*/ | |
// Bind function expression (closure) - 1M times | |
(function (numButtons) { | |
var btn = new sap.m.Button({text: "hello"}); | |
for(var i = 0; i < numButtons; i++) { | |
btn.attachPress(function (e) { console.log(e);}); | |
} | |
btn.placeAt('content'); | |
})(1000000); | |
// Bind named function - 1M times | |
(function (numButtons){ | |
function pressed(e) { | |
console.log(e); | |
} | |
var btn = new sap.m.Button({text: "hello"}); | |
for(var i = 0; i < numButtons; i++) { | |
btn.attachPress(pressed); | |
} | |
btn.placeAt('content'); | |
})(1000000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment