Attribute get and eval

JavaScript performance comparison

Revision 2 of this test case created

Preparation code

<div id="b-test-block" class="b-test-block" onclick="return {'b-test-block':{}}" bem-block-params="{&quot;b-test-block&quot;:{}}" />
<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.getAttribute(customAttrName);
          var params = attrValue ? JSON.parse(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.

Testing in unknown unknown
Test Ops/sec
Using "onclick"
var params = extractParamsOnClick(testElement);
pending…
Using custom attribute
var params = extractParamsCustomAttr(testElement);
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment