| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 227e749 commit 8bb03d1
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,41 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common.js'); | ||
| 3 | + const url = require('url'); | ||
| 4 | + const assert = require('assert'); | ||
| 5 | + | ||
| 6 | + const bench = common.createBenchmark(main, { | ||
| 7 | + type: common.urlDataTypes, | ||
| 8 | + e: [1], | ||
| 9 | + }); | ||
| 10 | + | ||
| 11 | + function main({ type, e }) { | ||
| 12 | + const data = common.bakeUrlData(type, e, false, false).map((i) => url.parse(i)); | ||
| 13 | + const obj = url.parse(data[0]); | ||
| 14 | + const noDead = { | ||
| 15 | + protocol: obj.protocol, | ||
| 16 | + auth: obj.auth, | ||
| 17 | + host: obj.host, | ||
| 18 | + hostname: obj.hostname, | ||
| 19 | + port: obj.port, | ||
| 20 | + pathname: obj.pathname, | ||
| 21 | + search: obj.search, | ||
| 22 | + hash: obj.hash, | ||
| 23 | + }; | ||
| 24 | + const len = data.length; | ||
| 25 | + // It's necessary to assign the values to an object | ||
| 26 | + // to avoid loop invariant code motion. | ||
| 27 | + bench.start(); | ||
| 28 | + for (let i = 0; i < len; i++) { | ||
| 29 | + const obj = data[i]; | ||
| 30 | + noDead.protocol = obj.protocol; | ||
| 31 | + noDead.auth = obj.auth; | ||
| 32 | + noDead.host = obj.host; | ||
| 33 | + noDead.hostname = obj.hostname; | ||
| 34 | + noDead.port = obj.port; | ||
| 35 | + noDead.pathname = obj.pathname; | ||
| 36 | + noDead.search = obj.search; | ||
| 37 | + noDead.hash = obj.hash; | ||
| 38 | + } | ||
| 39 | + bench.end(len); | ||
| 40 | + assert.ok(noDead); | ||
| 41 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,22 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common.js'); | ||
| 3 | + const url = require('url'); | ||
| 4 | + const assert = require('assert'); | ||
| 5 | + | ||
| 6 | + const bench = common.createBenchmark(main, { | ||
| 7 | + type: common.urlDataTypes, | ||
| 8 | + e: [1], | ||
| 9 | + }); | ||
| 10 | + | ||
| 11 | + function main({ e, type }) { | ||
| 12 | + const data = common.bakeUrlData(type, e, false, false); | ||
| 13 | + let result = url.parse(data[0]); // Avoid dead code elimination | ||
| 14 | + | ||
| 15 | + bench.start(); | ||
| 16 | + for (let i = 0; i < data.length; ++i) { | ||
| 17 | + result = url.parse(data[i]); | ||
| 18 | + } | ||
| 19 | + bench.end(data.length); | ||
| 20 | + | ||
| 21 | + assert.ok(result); | ||
| 22 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,40 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common.js'); | ||
| 3 | + const url = require('url'); | ||
| 4 | + const URL = url.URL; | ||
| 5 | + const assert = require('assert'); | ||
| 6 | + | ||
| 7 | + const bench = common.createBenchmark(main, { | ||
| 8 | + type: common.urlDataTypes, | ||
| 9 | + e: [1], | ||
| 10 | + }); | ||
| 11 | + | ||
| 12 | + function main({ type, e }) { | ||
| 13 | + const data = common.bakeUrlData(type, e, false, true); | ||
| 14 | + const obj = new URL(data[0]); | ||
| 15 | + const noDead = { | ||
| 16 | + protocol: obj.protocol, | ||
| 17 | + auth: `${obj.username}:${obj.password}`, | ||
| 18 | + host: obj.host, | ||
| 19 | + hostname: obj.hostname, | ||
| 20 | + port: obj.port, | ||
| 21 | + pathname: obj.pathname, | ||
| 22 | + search: obj.search, | ||
| 23 | + hash: obj.hash, | ||
| 24 | + }; | ||
| 25 | + const len = data.length; | ||
| 26 | + bench.start(); | ||
| 27 | + for (let i = 0; i < len; i++) { | ||
| 28 | + const obj = data[i]; | ||
| 29 | + noDead.protocol = obj.protocol; | ||
| 30 | + noDead.auth = `${obj.username}:${obj.password}`; | ||
| 31 | + noDead.host = obj.host; | ||
| 32 | + noDead.hostname = obj.hostname; | ||
| 33 | + noDead.port = obj.port; | ||
| 34 | + noDead.pathname = obj.pathname; | ||
| 35 | + noDead.search = obj.search; | ||
| 36 | + noDead.hash = obj.hash; | ||
| 37 | + } | ||
| 38 | + bench.end(len); | ||
| 39 | + assert.ok(noDead); | ||
| 40 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,20 +8,8 @@ const bench = common.createBenchmark(main, { | |||
| 8 | 8 | withBase: ['true', 'false'], | |
| 9 | 9 | type: common.urlDataTypes, | |
| 10 | 10 | e: [1], | |
| 11 | - method: ['legacy', 'whatwg'], | ||
| 12 | 11 | }); | |
| 13 | 12 | ||
| 14 | - function useLegacy(data) { | ||
| 15 | - const len = data.length; | ||
| 16 | - let result = url.parse(data[0]); // Avoid dead code elimination | ||
| 17 | - bench.start(); | ||
| 18 | - for (let i = 0; i < len; ++i) { | ||
| 19 | - result = url.parse(data[i]); | ||
| 20 | - } | ||
| 21 | - bench.end(len); | ||
| 22 | - return result; | ||
| 23 | - } | ||
| 24 | - | ||
| 25 | 13 | function useWHATWGWithBase(data) { | |
| 26 | 14 | const len = data.length; | |
| 27 | 15 | let result = new URL(data[0][0], data[0][1]); // Avoid dead code elimination | |
@@ -45,22 +33,10 @@ function useWHATWGWithoutBase(data) { | |||
| 45 | 33 | return result; | |
| 46 | 34 | } | |
| 47 | 35 | ||
| 48 | - function main({ e, method, type, withBase }) { | ||
| 36 | + function main({ e, type, withBase }) { | ||
| 49 | 37 | withBase = withBase === 'true'; | |
| 50 | - let noDead; // Avoid dead code elimination. | ||
| 51 | - let data; | ||
| 52 | - switch (method) { | ||
| 53 | - case 'legacy': | ||
| 54 | - data = common.bakeUrlData(type, e, false, false); | ||
| 55 | - noDead = useLegacy(data); | ||
| 56 | - break; | ||
| 57 | - case 'whatwg': | ||
| 58 | - data = common.bakeUrlData(type, e, withBase, false); | ||
| 59 | - noDead = withBase ? useWHATWGWithBase(data) : useWHATWGWithoutBase(data); | ||
| 60 | - break; | ||
| 61 | - default: | ||
| 62 | - throw new Error(`Unknown method ${method}`); | ||
| 63 | - } | ||
| 38 | + const data = common.bakeUrlData(type, e, withBase, false); | ||
| 39 | + const noDead = withBase ? useWHATWGWithBase(data) : useWHATWGWithoutBase(data); | ||
| 64 | 40 | ||
| 65 | 41 | assert.ok(noDead); | |
| 66 | 42 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments