Parameters in HTML attributes

JavaScript performance comparison

Test case created by Denis


Is using attributes in html tags for js-parameters fast enough?

Preparation code

<div id="target"></div>

<div id="config" data-param1 = "Some string" data-param2=""></div>

var myConf = {
param1: "Some string",
param2: ""
Benchmark.prototype.setup = function() {
    var target = document.getElementById('target');
    var s1;
    var s2;

Benchmark.prototype.teardown = function() {
    target.innerHTML = s1 + ' ' + s2;

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
HTML attributes
var htmlConf = document.getElementById('config');
s1 = htmlConf.getAttribute("data-param1");
s2 = htmlConf.getAttribute("data-param2");

Simple JS data
s1 = myConf.param1;
s2 = myConf.param2;

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers


Add a comment