Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
FAQ
Register
Log In
Run results for:
getRelativeUrl
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:121.0) Gecko/20100101 Firefox/121.0
Browser:
Firefox 121
Operating system:
Mac OS X 10.15
Device Platform:
Desktop
Date tested:
2 years ago
Benchmark engine:
Benchmark.js
getRelativeUrl
10.8M/s
RegExp
2.1M/s
new URL
517K/s
View exact numbers
Test name
Executions per second
✓
getRelativeUrl
10,841,757 Ops/sec
RegExp
2,104,206 Ops/sec
new URL
516,661 Ops/sec
Script Preparation code:
function getRelativeUrl(url) { try { if (url.indexOf('http://') > -1) { return url.substring(url.indexOf('/', 7) + 1); } if (url.indexOf('https://') > -1) { return url.substring(url.indexOf('/', 8) + 1); } throw new Error('invalid url'); } catch (e) { console.error(e); return url; } };
Tests:
new URL
return new URL('https://is5-ssl.mzstatic.com/image/thumb/Purple126/v4/00/33/2e/00332e58-b196-82cf-1231-82d81d6fe477/AppIcon_TikTok-0-0-1x_U007emarketing-0-0-0-7-0-0-sRGB-0-0-0-GLES2_U002c0-512MB-85-220-0-0.png/512x0w.png').origin;
RegExp
return 'https://is5-ssl.mzstatic.com/image/thumb/Purple126/v4/00/33/2e/00332e58-b196-82cf-1231-82d81d6fe477/AppIcon_TikTok-0-0-1x_U007emarketing-0-0-0-7-0-0-sRGB-0-0-0-GLES2_U002c0-512MB-85-220-0-0.png/512x0w.png'.match(/^(?:https?:\/\/)?(?:[^@\n]+@)?(?:www\.)?([^:\/\n?]+)(\/[^?#]*)?(\?[^#]*)?/)[0]
getRelativeUrl
return getRelativeUrl('https://is5-ssl.mzstatic.com/image/thumb/Purple126/v4/00/33/2e/00332e58-b196-82cf-1231-82d81d6fe477/AppIcon_TikTok-0-0-1x_U007emarketing-0-0-0-7-0-0-sRGB-0-0-0-GLES2_U002c0-512MB-85-220-0-0.png/512x0w.png')