<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
const xhr = new XMLHttpRequest();
xhr.open('GET', 'https://www.googleapis.com/discovery/v1/apis');
xhr.onload = () => console.log(JSON.parse(xhr.responseText));
xhr.send();
fetch('https://www.googleapis.com/discovery/v1/apis')
.then(response => response.json())
.then(console.log)
axios.get('https://www.googleapis.com/discovery/v1/apis')
.then((response) => response.json())
.then(console.log);
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
xhr | |
fetch | |
axios |
Test name | Executions per second |
---|---|
xhr | 1261.1 Ops/sec |
fetch | 1206.6 Ops/sec |
axios | 1231.9 Ops/sec |
Overview
The provided JSON represents a JavaScript microbenchmark test case on the MeasureThat.net website. The benchmark compares the performance of three different methods: XHR (XMLHttpRequest), fetch, and axios. The goal is to determine which method is the fastest.
What is tested
Three individual test cases are defined:
response.json()
method and logged to the console.response.data
property (not response.json()
, which is why this might seem slightly different from fetch) and logged to the console.Options compared
The three options are:
Pros and Cons of each option
Library usage
The axios
library is used in this benchmark. Axios is a popular JavaScript library that simplifies HTTP requests by providing a more intuitive API than traditional XHR or the fetch API. It also offers additional features like caching, error handling, and debugging tools.
Special JS feature or syntax
There are no special JavaScript features or syntax used in this benchmark. All three options rely on standard JavaScript and DOM APIs to make the HTTP requests.
Other alternatives
If you're looking for alternative methods to making HTTP requests, some popular options include:
Keep in mind that each option has its strengths and weaknesses, and the choice of which to use will depend on your specific needs and preferences.