add performance calc
This commit is contained in:
@@ -19,6 +19,8 @@ export default function UserEffect() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const start = performance.now(); // Start measuring performance
|
||||||
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
|
||||||
// Using AbortController to cancel the fetch request if the component unmounts
|
// Using AbortController to cancel the fetch request if the component unmounts
|
||||||
@@ -33,6 +35,9 @@ export default function UserEffect() {
|
|||||||
return response.json();
|
return response.json();
|
||||||
}).then(data => {
|
}).then(data => {
|
||||||
setUser(data);
|
setUser(data);
|
||||||
|
const end = performance.now(); // End measuring performance
|
||||||
|
const timeTaken = end - start; // Calculate the time taken
|
||||||
|
console.log(`Fetch completed in ${Math.round(timeTaken)} milliseconds`);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
console.error("There was a problem with the fetch operation:", error);
|
console.error("There was a problem with the fetch operation:", error);
|
||||||
|
|||||||
Reference in New Issue
Block a user