Template strings vs String.raw vs Concats (v3)

Revision 3 of this benchmark created on


Setup

var RUNS = 100;

function ttl(obj, ...args) {
	return String.raw(obj, ...args);
}

function ttlConcats(obj, ...args) {
	let out = '';
	const argsLen = args.length;
	for (let i = 0; i <= argsLen; i++) {
		out += obj[i];
		if (i === argsLen) return;

		out += args[i];
	}
	return out;
}

Teardown

delete runs;
delete ttl;
delete ttlConcats;

Test runner

Ready to run.

Testing in
TestOps/sec
Template string
for (let i = 0; i < RUNS; i++)
	`hello ${'world'}`;
ready
TTL - String.raw
for (let i = 0; i < RUNS; i++)
	ttl`hello ${'world'}`;
ready
TTL - Concats
for (let i = 0; i < RUNS; i++)
	ttlConcats`hello ${'world'}`;
ready
Template string [NESTED]
for (let i = 0; i < RUNS; i++)
	`hello ${'world'} ${`nested ${1}`}`;
ready
TTL - String.raw [NESTED]
for (let i = 0; i < RUNS; i++)
	ttl`hello ${'world'} ${ttl`nested ${1}`}`;
ready
TTL - Concats [NESTED]
for (let i = 0; i < RUNS; i++)
	ttlConcats`hello ${'world'} ${ttlConcats`nested ${1}`}`;
ready

Revisions

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