mit string operatation vs .html and .addClass

JavaScript performance comparison

Test case created by

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

      
<script>
Benchmark.prototype.setup = function() {
  var options = {};
    options.text = "bier"

};
</script>

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
String
var $controlUI = $('<div class="gm-style-mtc">' + options.text + '</div>');
pending…
.html .addclass
var $controlUI = $('<div />');
$controlUI.addClass('gm-style-mtc');
 $controlUI.html(options.text);
pending…
.html
var $controlUI = $('<div class="gm-style-mtc" />');
$controlUI.html(options.text);
pending…
addClass
var $controlUI = $('<div>' + options.text + '</div>');
$controlUI.addClass('gm-style-mtc');
pending…

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

0 Comments