startsWith/endsWith vs split

Benchmark created on


Setup

const locations = [
    '/_design-spec-selector',
    '/apps',
    '/brand',
    '/class/join',
    '/contributors/upload',
    '/creator-hub',
    '/creators/element',
    '/creators/my-items',
    '/creators/performance',
    '/creators/resources',
    '/creators/resources/videos/:videoId',
    '/creators/resources/videos',
    '/creators/template',
    '/design-reviews',
    '/discover',
    '/earnings',
    '/edu-signup',
    '/folder',
    '/groups',
    '/icons/',
    '/magic-home',
    '/menu',
    '/mockups',
    '/nfp-signup',
    '/offline-designs',
    '/p',
    '/planner',
    '/portfolio',
    '/pro-features',
    '/product-photos',
    '/projects',
    '/rewards',
    '/scheduled',
    '/search',
    '/shared-with-you',
    '/smartmockups',
    '/starred',
    '/team/join',
    '/teams',
    '/teams/groups',
    '/trash',
    '/your-apps',
    '/your-projects',
	'/design/DAAAAAAA/xyz/edit',
];

Test runner

Ready to run.

Testing in
TestOps/sec
startsWith/endsWith
for (let i = 0; i++; i < locations.length) {
	let location = locations[i];
	let result = location.startsWith('/design/') && location.endsWith('/edit');
}
ready
split
for (let i = 0; i++; i < locations.length) {
	let location = locations[i];
	
	let parts = location.split('/');
	let startsWith = parts[1];
	let endsWith = parts[parts.length - 1];
	
	let result = startsWith === 'design' && endsWith === 'edit';
}
ready

Revisions

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