prefix string

Benchmark created on


Description

combine a string with a prefix

Setup

const prefix = '_this_is_a_prefix_';

const strings_count = 1e6;

const string_short_length = 10;
const strings_short = [];
for(let s = 0; s < strings_count; ++s) {
	strings_short.push(
	   (Math.random() + 1)
	   .toString(36)
	   .substring(string_short_length);
	);
}

const string_medium_length = 100;
const strings_medium = [];
for(let s = 0; s < strings_count; ++s) {
	strings_medium.push(
	   (Math.random() + 1)
	   .toString(36)
	   .substring(string_medium_length);
	);
}


const string_long_length = 1000;
const strings_medium = [];
for(let s = 0; s < strings_count; ++s) {
	strings_long.push(
	   (Math.random() + 1)
	   .toString(36)
	   .substring(string_long_length);
	);
}


Test runner

Ready to run.

Testing in
TestOps/sec
short string with plus operator
const prefixed = [];
strings_short.forEach( s => {
	prefixed.push(prefix + s)
});
ready
short string with template string
const prefixed = [];
strings_short.forEach( s => {
	prefixed.push(`${prefix}${s}`)
});
ready
medium string with plus operator
const prefixed = [];
strings_medium.forEach( s => {
	prefixed.push(prefix + s)
});
ready
medium string with template string
const prefixed = [];
strings_medium.forEach( s => {
	prefixed.push(`${prefix}${s}`)
});
ready
long string with plus operator
const prefixed = [];
strings_long.forEach( s => {
	prefixed.push(prefix + s)
});
ready
long string with template string
const prefixed = [];
strings_long.forEach( s => {
	prefixed.push(`${prefix}${s}`)
});
ready

Revisions

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