Splitting and trimming (v3)

Revision 3 of this benchmark created on


Setup

const regex = /\s*,\s*/;
const cases = {
	noOp: "press",
	workful: "press,close",
	absurd: " press , close ",
};

Test runner

Ready to run.

Testing in
TestOps/sec
No-op with nested trims
const eventNames = cases.noOp.trim();
const splits = eventNames.split(",");

// Give the benchmark some work to do so that
// it doesn't optimise out the for loop
// contents
let acc = "";
for(let i = 0; i < splits.length; i++){
	const eventName = splits[i].trim();
	acc += eventName;
}
ready
No-op with regex
const splits = cases.noOp.trim().split(regex);

// Give the benchmark some work to do so that
// it doesn't optimise out the for loop
// contents
let acc = "";
for(let i = 0; i < splits.length; i++){
	const eventName = splits[i];
	acc += eventName;
}
ready
Workful with nested trims
const eventNames = cases.workful.trim();
const splits = eventNames.split(",");

// Give the benchmark some work to do so that
// it doesn't optimise out the for loop
// contents
let acc = "";
for(let i = 0; i < splits.length; i++){
	const eventName = splits[i].trim();
	acc += eventName;
}
ready
Workful with regex
const splits = cases.workful.trim().split(regex);

// Give the benchmark some work to do so that
// it doesn't optimise out the for loop
// contents
let acc = "";
for(let i = 0; i < splits.length; i++){
	const eventName = splits[i];
	acc += eventName;
}
ready
Absurd with nested trims
const eventNames = cases.absurd.trim();
const splits = eventNames.split(",");

// Give the benchmark some work to do so that
// it doesn't optimise out the for loop
// contents
let acc = "";
for(let i = 0; i < splits.length; i++){
	const eventName = splits[i].trim();
	acc += eventName;
}
ready
Absurd with regex
const splits = cases.absurd.trim().split(regex);

// Give the benchmark some work to do so that
// it doesn't optimise out the for loop
// contents
let acc = "";
for(let i = 0; i < splits.length; i++){
	const eventName = splits[i];
	acc += eventName;
}
ready

Revisions

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