Native XHR vs jQuery ajax

JavaScript performance comparison

Revision 25 of this test case created by Emanuele Sabellico

Preparation code

<script src="http://code.jquery.com/jquery-2.1.4.min.js">
</script>
<script src="https://raw.githubusercontent.com/github/fetch/master/fetch.js"></script>
      
<script>
Benchmark.prototype.setup = function() {
  window.done = function(){ deferred.resolve()}
  window.url = 'https://raw.githubusercontent.com/github/fetch/master/fetch.js'

};
</script>

Preparation code output

<script src="https://raw.githubusercontent.com/github/fetch/master/fetch.js"></script>

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
fetch
// async test
fetch(url).then(done)
pending…
Native XHR
// async test
var xhr = new XMLHttpRequest();
xhr.open("GET", url);
xhr.onreadystatechange = function() {
  if (xhr.readyState == 4) {
    done(xhr);
  }
}
xhr.send();
pending…
Native XHR Onload
// async test
var xhr = new XMLHttpRequest();
xhr.onload = done;
xhr.open("GET", url, true);
xhr.send(null);
pending…
jQuery ajax
// async test
var request = $.get(url, done);
pending…

Compare results of other browsers

Revisions

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

0 Comments