Attribute get and eval
JavaScript performance comparison
Preparation code
<div id="b-test-block" class="b-test-block" onclick="return {'b-test-block':{}}" bem-block-params="return {'b-test-block':{}}" />
<script>
Benchmark.prototype.setup = function() {
var extractParamsOnClick = function(element) {
var fn = element.onclick;
var params = fn ? fn() : {};
return params;
}
var customAttrName = 'bem-block-params';
var extractParamsCustomAttr = function(element) {
var attrValue = element.hasAttribute(customAttrName) ? element.getAttribute(customAttrName) : null;
var params = attrValue ? Function(attrValue)() : {};
return params;
}
var testElement = document.getElementById('b-test-block');
};
</script>
Preparation code output
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Using "onclick" |
|
pending… |
Using custom attribute |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments