Attribute get and eval

JavaScript performance comparison

Test case created by Alexey Kuzmin

Preparation code

<div id="b-test-block" class="b-test-block" onclick="return {'b-test-block':{}}" bem-block-params="return {'b-test-block':{}}" />
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');

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