Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
NATIVE XHR VS JQUERY
(version: 1)
Comparing performance of:
NATIVE XHR vs NATIVE XHR 2 vs NATIVE FETCH vs JQUERY AJAX vs JQUERY AJAX ASYNC vs JQUERY GET vs JQUERY GET 2 vs JQUERY GETJSON
Created:
6 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
Script Preparation code:
function showResult(data) { console.log(data); } var newUrl = "https://www.googleapis.com/discovery/v1/apis";
Tests:
NATIVE XHR
var xhr = new XMLHttpRequest(); xhr.open("GET", newUrl, true); xhr.onreadystatechange = function() { if (xhr.readyState === 4) { showResult(xhr); } } xhr.send();
NATIVE XHR 2
var xhr = new XMLHttpRequest(); xhr.onload = showResult; xhr.open("GET", newUrl, true); xhr.send();
NATIVE FETCH
var request = fetch(newUrl).then(showResult);
JQUERY AJAX
var request = $.ajax({ type: "GET", url: newUrl, success: showResult, data: null });
JQUERY AJAX ASYNC
var request = $.ajax({ type: "GET", async: true, url: newUrl, success: showResult, data: null });
JQUERY GET
var request = $.get(newUrl, showResult);
JQUERY GET 2
var request = $.get(newUrl).done(showResult);
JQUERY GETJSON
$.getJSON(newUrl, null, showResult);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (8)
Previous results
Fork
Test case name
Result
NATIVE XHR
NATIVE XHR 2
NATIVE FETCH
JQUERY AJAX
JQUERY AJAX ASYNC
JQUERY GET
JQUERY GET 2
JQUERY GETJSON
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the provided benchmark and explain what's being tested, compared, and their pros/cons. **Benchmark Overview** The benchmark tests different ways to make an HTTP GET request in JavaScript. The test cases compare the performance of native XMLHttpRequest (XHR) with jQuery-based approaches. **What is Tested** 1. **Native XHR**: This refers to using the built-in `XMLHttpRequest` object to make a GET request. 2. **jQuery XHR**: This involves using jQuery's `ajax()` method to make a GET request. 3. **jQuery Fetch**: This uses the modern `fetch()` API, which is a part of JavaScript (ECMAScript 2015+). **Comparison** The benchmark compares the performance of each approach in terms of: 1. **Execution Frequency Per Second (ExecutionsPerSecond)**: This measures how many requests are executed per second. **Options Compared** 1. **xhr.onload = showResult**: This approach sets up a callback function for when the request is complete. 2. **xhr.onreadystatechange = function() {...}``: This approach uses the `readystatechange` event to check the request status. 3. **xhr.send()`: This simply sends the request without waiting for a response. **Pros and Cons** 1. **Native XHR (xhr.onload = showResult)**: * Pros: Native, no dependencies on jQuery. * Cons: May require more code to handle errors and callbacks. 2. **jQuery XHR ( xhr.onload = showResult )**: * Pros: Easier to use than native XHR, handles errors and callbacks automatically. * Cons: Dependent on jQuery library, which may add overhead. 3. **jQuery Fetch ( fetch() API)**: * Pros: Modern, easy to use, and efficient. * Cons: Requires support for ECMAScript 2015+ features. **Other Considerations** 1. **Async/await syntax**: None of the test cases use async/await syntax, which is a more modern way of handling asynchronous code in JavaScript. 2. **Browser Support**: The benchmark only tests Chrome 74, so results may vary across other browsers. **Alternatives** If you want to explore other alternatives, here are a few: 1. **Axios**: A popular library for making HTTP requests in JavaScript that's not included in this benchmark. 2. **fetch-polyfill**: A polyfill for the modern `fetch()` API that allows support for older browsers. Keep in mind that these alternatives may have different performance characteristics and trade-offs compared to the approaches tested in this benchmark.
Related benchmarks:
Native XHR vs jQuery Ajax
Native XHR vs jQuery Ajax3
fetch vs ajax call - updated 2021
fetch vs ajax call V2
Comments
Confirm delete:
Do you really want to delete benchmark?