ES6 String Literals vs. String Concatenation With Var Use (v48)

Revision 48 of this benchmark created on


Setup

var precalculatedIso = (new Date()).toISOString();

Test runner

Ready to run.

Testing in
TestOps/sec
ES6 with variable
var test = "<body>"+
  "<article>"+
    "<time datetime='" + precalculatedIso +"'>"+ precalculatedIso +"</time>"+
  "</article>"+
"</body>";

(() => {
	for(var i = 0; i < 10000; ++i) {
		const str = `${Math.random()}${test}`;
		console.log(str)
	}
})()
ready
String concatenation with variable
var test = "<body>"+
  "<article>"+
    "<time datetime='" + precalculatedIso +"'>"+ precalculatedIso +"</time>"+
  "</article>"+
"</body>";

(() => {
	for(var i = 0; i < 10000; ++i) {
		const str = Math.random() + test;
		console.log(str)
	}
})()
ready
ES6 with function
var test = "<body>"+
  "<article>"+
    "<time datetime='" + (new Date()).toISOString() +"'>"+ (new Date()).toISOString() +"</time>"+
  "</article>"+
"</body>";

(() => {
	for(var i = 0; i < 10000; ++i) {
		const str = `${Math.random()}${test}`;
		console.log(str)
	}
})()
ready
String concatenation with function
var test = "<body>"+
  "<article>"+
    "<time datetime='" + (new Date()).toISOString() +"'>"+ (new Date()).toISOString() +"</time>"+
  "</article>"+
"</body>";

(() => {
	for(var i = 0; i < 10000; ++i) {
		const str = Math.random() + test;
		console.log(str)
	}
})()
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.