<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/superagent"></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);
superagent.get('https://www.googleapis.com/discovery/v1/apis')
.then(res => {
console.log(res.body);
});
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
xhr | |
fetch | |
axios | |
superagent |
Test name | Executions per second |
---|---|
xhr | 13149.5 Ops/sec |
fetch | 11557.9 Ops/sec |
axios | 8378.0 Ops/sec |
superagent | 12041.6 Ops/sec |
Let's dive into the world of JavaScript microbenchmarks on MeasureThat.net.
Overview
The provided benchmark tests four different methods for making HTTP requests to retrieve data from an API endpoint: XMLHttpRequest (XHR), fetch, axios, and superagent. The goal is to compare their performance in terms of execution speed and number of executions per second.
Options Compared
Pros and Cons
Library Descriptions
Special JS Features or Syntax
None mentioned in this benchmark.
Alternative Approaches
Benchmark Preparation Code
The provided HTML code includes the necessary scripts for axios and superagent to be executed:
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/superagent"></script>
This ensures that both libraries are loaded and available for use in the benchmark test cases.