String streamer

Benchmark created on


Setup

let str = "";
for (let i = 0; i < 1e7; i ++) {
	str += "G1 X10 Y10 Z10 E10.01\n";
}

Test runner

Ready to run.

Testing in
TestOps/sec
str.split
function split(str) {
	return str.split("\n");
}

for (const ln of split(str)) {
	//
}
ready
string streamer
function* stream(str) {
	let part = "";
	for (let i = 0; i < str.length; i ++) {
		const char = str[i];
		if (char === "\n") {
		  yield part;
		  part = "";	
		} else {
		  part = "";
		}
	}
}

for (const ln of stream(str)) {
	//
}
ready

Revisions

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