<div id="test"></div>
fetch('https://jsonplaceholder.typicode.com/todos', {
method: 'GET'
})
.then((response) => {
return response.text();
})
.then((data) => {
console.log(data);
});
fetch('https://jsonplaceholder.typicode.com/todos', {
method: 'GET',
cache: 'no-store'
})
.then((response) => {
return response.text();
})
.then((data) => {
console.log(data);
});
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Fetch (default) | |
Fetch (no-store) |
Test name | Executions per second |
---|---|
Fetch (default) | 1937.6 Ops/sec |
Fetch (no-store) | 1828.7 Ops/sec |
Let's dive into the world of measuring JavaScript performance.
What is being tested?
The benchmark is testing two different approaches for making HTTP GET requests using the fetch
API: with caching enabled (default
) and without caching enabled (no-store
). The test cases are designed to measure the execution time, number of executions per second, and other metrics for both scenarios.
Options being compared
In this case, we have only two options being compared:
cache
property in the fetch
options object to enable caching. The request is cached by the browser or a proxy server, which means that subsequent requests for the same URL will use the cached response instead of re-downloading it from the server.cache
property in the fetch
options object, effectively disabling caching. The request is always sent to the server, even if it's a repeat request.Pros and Cons
Here are some pros and cons of each approach:
Library usage
In this benchmark, the fetch
API is used to make HTTP GET requests. The fetch
API is a modern JavaScript API introduced in 2015, which allows you to make asynchronous HTTP requests without requiring manual implementation of AJAX-like code.
Special JS feature or syntax
There doesn't appear to be any special JavaScript features or syntax used in this benchmark. The test cases are written in standard JavaScript and use the fetch
API as described above.
Other alternatives
If you're interested in exploring alternative approaches for making HTTP requests, here are some options:
fetch
API.http
or https
to make HTTP requests.Overall, this benchmark provides a useful insight into the performance differences between fetching with caching enabled versus without caching.