Created
March 27, 2019 07:56
-
-
Save SmolinPavel/65be8d446916516a248785a4dd11adc5 to your computer and use it in GitHub Desktop.
Measuring performance (spead vs Array.forEach)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>JS Sandbox</title> | |
</head> | |
<body> | |
<script> | |
const object = { | |
test: "test", | |
paul: "paul", | |
morning: { test: "test", paul: "paul" } | |
}; | |
let test1 = { test: "default" }; | |
const t0 = performance.now(); | |
Object.keys(object).forEach(item => { | |
test1[item] = object[item]; | |
}); | |
const t1 = performance.now(); | |
console.log("Call to forEach took " + (t1 - t0) + " milliseconds."); | |
let test2 = { test: "default" }; | |
const t2 = performance.now(); | |
test2 = { ...test2, ...object }; | |
const t3 = performance.now(); | |
console.log("Call to spread took " + (t3 - t2) + " milliseconds."); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Spread seems to be faster in my checks: