Last active
March 14, 2017 17:08
-
-
Save joliss/4171cf62ab15c8bf7eb6e4e81eeb8bdc to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/node | |
const N = 1000000; | |
// 130 ms | |
(function() { | |
console.time('+='); | |
let a = ''; | |
for (let i = 0; i < N; i++) { | |
a += 'x'; | |
} | |
console.timeEnd('+='); | |
})(); | |
// 70 ms | |
(function() { | |
console.time('= +'); | |
let a = ''; | |
for (let i = 0; i < N; i++) { | |
a = a + 'x'; | |
} | |
console.timeEnd('= +'); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
V8 5.9 with turbofan. The generated optimized code looks the same to me. Seems like the first function is always the slower one. So
+=
is perfectly fine to use in the future. You can download Node with newest V8 for Ubuntu from here.Old V8 (Node 7) with crankshaft: