Split vs Substring

Benchmark created on


Setup

const title = "This is a very long title with multiple words";

Test runner

Ready to run.

Testing in
TestOps/sec
Split
const split = title.split(' ');
for (var i = 0; i < split.length; i++) {
	var topLine = split.slice(0, i).join(' ');
	var bottomLine = split.slice(i, split.length).join(' ');
}
ready
Substring
var lastIndex;
var nextIndex = -1;
do {
	var topLine = title.substring(0, nextIndex);
	var bottomLine = title.substring(nextIndex + 1);
	lastIndex = nextIndex + 1;
} while ((nextIndex = title.indexOf(' ', lastIndex)) != -1);
ready

Revisions

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