This repository has been archived by the owner on Jul 15, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
/* all -a implementations below are faster findLastFile-a: 964ms findLastFile-b: 2583ms findQueryOrFragment-a: 523ms findQueryOrFragment-b: 729ms findFragment-a: 690ms findFragment-b: 362ms symbol-a: 58ms symbol-b: 64ms */ var basePath = '/..#?'; var pos = -1; console.time('findLastFile-a'); var re = /(?:[\/\\](?!(?:\.|%2[eE]){2})[^\/\\?#]*)?(?:$|[?#])/g; for (var i = 0; i < 10000000; i++) { pos = re.exec(basePath).index; } console.timeEnd('findLastFile-a'); console.time('findLastFile-b'); var _resolvePathDoubleDots = /^(?:\.|%2[eE]){2}$/; var pathEnd, t; for (var i = 0; i < 10000000; i++) { var qPos = basePath.indexOf('?'), hashPos = basePath.indexOf('#'); pos = (qPos === -1 || hashPos !== -1 && hashPos < qPos) ? hashPos : qPos; pathEnd = pos === -1 ? undefined : pos; // _composeOriginSchemePath() normalized path to have at least the first / t = Math.max(basePath.lastIndexOf('/', pathEnd), basePath.lastIndexOf('\\', pathEnd)); // update pos as t only when the filename (after slash and until ?/#) is not .. or equiv. !_resolvePathDoubleDots.test(basePath.slice(t + 1, pathEnd)) && (pos = t); } console.timeEnd('findLastFile-b'); console.time('findQueryOrFragment-a'); var t, _reQueryOrFragment = /[?#]/; for (var i = 0; i < 10000000; i++) { (t = _reQueryOrFragment.exec(basePath)) && (pos = t.index); } console.timeEnd('findQueryOrFragment-a'); console.time('findQueryOrFragment-b'); for (var i = 0; i < 10000000; i++) { var qPos = basePath.indexOf('?'), hashPos = basePath.indexOf('#'); pos = (qPos === -1 || hashPos !== -1 && hashPos < qPos) ? hashPos : qPos; } console.timeEnd('findQueryOrFragment-b'); console.time('findFragment-a'); var t, _reFragment = /#/; for (var i = 0; i < 10000000; i++) { (t = _reFragment.exec(basePath)) && (pos = t.index); } console.timeEnd('findFragment-a'); console.time('findFragment-b'); for (var i = 0; i < 10000000; i++) { pos = basePath.indexOf('#'); } console.timeEnd('findFragment-b'); var len = basePath.length; console.time('symbol-a'); function symbolB (path, i) { switch(path.charCodeAt(i)) { case 47: case 92: return 1; case 35: case 63: return 2; } return 0; } for (var i = 0; i < 10000000; i++) { symbolB(basePath, i % len); } console.timeEnd('symbol-a'); console.time('symbol-b'); function symbolA (path, i) { var charCode = path.charCodeAt(i); return charCode === 47 || charCode === 92 ? 1 : charCode === 35 || charCode === 63 ? 2 : 0; } for (var i = 0; i < 10000000; i++) { symbolA(basePath, i % len); } console.timeEnd('symbol-b');
- Loading branch information