Attribute get and eval

JavaScript performance comparison

Revision 3 of this test case created

Preparation code

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;
    function createTestElement() {
        var div = document.createElement('div');
        div.innerHTML = '<div id="b-test-block" class="b-test-block" onclick="return {&quot;b-test-block&quot;:{}}" bem-block-params="{&quot;b-test-block&quot;:{}}" />';
        return div.firstChild;

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

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