Created
June 27, 2024 21:46
-
-
Save JanMiksovsky/25770fd76cf350ff01d746b040690285 to your computer and use it in GitHub Desktop.
Measure difference in performance of writeFile(string value) vs writeFile(String object)
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
import fs from "node:fs/promises"; | |
// Create a 1MB string value to a file | |
const string = "a".repeat(1000000); | |
const startValue = performance.mark("string"); | |
await fs.writeFile("1MB.txt", string); | |
const measureValue = performance.measure("write string value", startValue); | |
console.log(`${measureValue.name}: ${measureValue.duration}ms`); | |
// Write the string as a String object | |
const object = new String(string); | |
const startObject = performance.mark("String"); | |
await fs.writeFile("1MBString.txt", object); | |
const measureObject = performance.measure("write String object", startObject); | |
console.log(`${measureObject.name}: ${measureObject.duration}ms`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment