Template Literal vs String.Replace

Benchmark created on


Setup

var baseText = 'Erosion takes 1 year'
var n = '123';
var m = 'units';

function replace(str, a, b) {
	return str.replace('1 year', `${a} ${b}`);
}

function literal(a, b) {
	return `Erosion takes ${a} ${b}`;
}

Test runner

Ready to run.

Testing in
TestOps/sec
Template Literal
literal(n, m);
ready
String Replace
replace(baseText, n, m);
ready

Revisions

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