Created
January 22, 2018 18:03
-
-
Save andrewodri/2c351801cc14dab33d04280e13a25075 to your computer and use it in GitHub Desktop.
String concatenation versus template literals
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
var precalculatedIso = (new Date()).toISOString(); | |
console.time("es6Variable"); | |
for(var i = 0; i < 100000; i++){ | |
var test = `<body> | |
<article> | |
<time datetime='${ precalculatedIso }'>${ precalculatedIso }</time> | |
</article> | |
</body>`; | |
} | |
console.timeEnd("es6Variable"); | |
console.time("stringVariable"); | |
for(var i = 0; i < 100000; i++){ | |
var test = "<body>"+ | |
"<article>"+ | |
"<time datetime='" + precalculatedIso +"'>"+ precalculatedIso +"</time>"+ | |
"</article>"+ | |
"</body>"; | |
} | |
console.timeEnd("stringVariable"); | |
console.time("es6Function"); | |
for(var i = 0; i < 100000; i++){ | |
var test = `<body> | |
<article> | |
<time datetime='${ (new Date()).toISOString() }'>${ (new Date()).toISOString() }</time> | |
</article> | |
</body>`; | |
} | |
console.timeEnd("es6Function"); | |
console.time("stringFunction"); | |
for(var i = 0; i < 100000; i++){ | |
var test = "<body>"+ | |
"<article>"+ | |
"<time datetime='" + (new Date()).toISOString() +"'>"+ (new Date()).toISOString() +"</time>"+ | |
"</article>"+ | |
"</body>"; | |
} | |
console.timeEnd("stringFunction"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment