Template strings vs TTL (v5)

Revision 5 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
Template string [NESTED]
for (let i = 0; i < RUNS; i++)
	`hello ${'world'} ${`nested ${1}`}`;
ready
Plus (+) Concat
for (let i = 0; i < RUNS; i++)
	'hello ' + 'world';
ready
Plus (+) Concat [NESTED]
for (let i = 0; i < RUNS; i++)
  'hello ' + 'world' + 'nested ' + 1;
ready
Tagged Template Literal - String.raw
for (let i = 0; i < RUNS; i++)
	ttl`hello ${'world'}`;
ready
Tagged Template Literal - String.raw [NESTED]
for (let i = 0; i < RUNS; i++)
	ttl`hello ${'world'} ${ttl`nested ${1}`}`;
ready
Tagged Template Literal - No rest/spread
for (let i = 0; i < RUNS; i++)
	ttlConcats`hello ${'world'}`;
ready
Tagged Template Literal - No rest/spread [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.