predefined vs new query

Benchmark created by richard lee on


Description

see if it is quick to pre define your jquery objects in certain instances or not.

Preparation HTML

<div id="box">
  <h1>
    hello
  </h1>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
unique call
$("#box").find("h1");
$("#box").find("h1").text("go1");
$("#box").find("h1").text("go2");
$("#box").find("h1").text("go3");
ready
predefined call
var theBox = $("#box").find("h1");
theBox.text("go1");
theBox.text("go2");
theBox.text("go3");
ready
var theBox = $("#box").find("h1");

function update(string) {
  theBox.text(string);
}

update("go1");
update("go2");
update("go3");
ready
extracted function 2
var theBox = $("#box").find("h1");

var update = function(string) {
  theBox.text(string);
}

update("go1");
update("go2");
update("go3");
ready
extracted function 3
var theBox = $("#box").find("h1");

function update(obj,string) {
  obj.text(string);
}

update(theBox,"go1");
update(theBox,"go2");
update(theBox,"go3");
ready
extracted function 4
var theBox = $("#box").find("h1");

var update = function(obj,string) {
  obj.text(string);
}

update(theBox,"go1");
update(theBox,"go2");
update(theBox,"go3");
ready

Revisions

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

  • Revision 1: published by richard lee on
  • Revision 2: published on
  • Revision 3: published by richard lee on
  • Revision 4: published by richard lee on
  • Revision 5: published by Gaurav Vaish on