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;:{}}" />
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');

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);
Using custom attribute
var params = extractParamsCustomAttr(testElement);

Compare results of other browsers


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:


Comment form temporarily disabled.

Add a comment