Parameters in HTML attributes

JavaScript performance comparison

Test case created by Denis

Info

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="http://google.com"></div>

<script>
var myConf = {
param1: "Some string",
param2: "http://google.com"
}
</script>
<script>
Benchmark.prototype.setup = function() {
    var target = document.getElementById('target');
    var s1;
    var s2;
};

Benchmark.prototype.teardown = function() {
    target.innerHTML = s1 + ' ' + s2;
};
</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
HTML attributes
var htmlConf = document.getElementById('config');
s1 = htmlConf.getAttribute("data-param1");
s2 = htmlConf.getAttribute("data-param2");

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

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

Compare results of other browsers

0 comments

Add a comment