| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,9 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | 3 | const common = require('../common.js'); | |
| 4 | - const ClientRequest = require('http').ClientRequest; | ||
| 4 | + const { ClientRequest } = require('http'); | ||
| 5 | + const assert = require('assert'); | ||
| 6 | + | ||
| 5 | 7 | const types = Object.keys(common.urls) | |
| 6 | 8 | .filter((i) => common.urls[i] | |
| 7 | 9 | .startsWith('http://')); | |
@@ -15,36 +17,43 @@ const bench = common.createBenchmark(main, { | |||
| 15 | 17 | function noop() {} | |
| 16 | 18 | ||
| 17 | 19 | function main({ url: type, arg, e }) { | |
| 18 | - e = +e; | ||
| 20 | + e = Number(e); | ||
| 19 | 21 | const data = common.bakeUrlData(type, e, false, false) | |
| 20 | 22 | .filter((i) => i.startsWith('http://')); | |
| 21 | 23 | const len = data.length; | |
| 22 | - var result; | ||
| 23 | - var i; | ||
| 24 | - if (arg === 'options') { | ||
| 25 | - const options = data.map((i) => ({ | ||
| 26 | - path: new URL(i).path, createConnection: noop | ||
| 27 | - })); | ||
| 28 | - bench.start(); | ||
| 29 | - for (i = 0; i < len; i++) { | ||
| 30 | - result = new ClientRequest(options[i]); | ||
| 24 | + let result; | ||
| 25 | + switch (arg) { | ||
| 26 | + case 'options': { | ||
| 27 | + const options = data.map((i) => ({ | ||
| 28 | + path: new URL(i).path, createConnection: noop | ||
| 29 | + })); | ||
| 30 | + bench.start(); | ||
| 31 | + for (let i = 0; i < len; i++) { | ||
| 32 | + result = new ClientRequest(options[i]); | ||
| 33 | + } | ||
| 34 | + bench.end(len); | ||
| 35 | + break; | ||
| 36 | + } | ||
| 37 | + case 'URL': { | ||
| 38 | + const options = data.map((i) => new URL(i)); | ||
| 39 | + bench.start(); | ||
| 40 | + for (let i = 0; i < len; i++) { | ||
| 41 | + result = new ClientRequest(options[i], { createConnection: noop }); | ||
| 42 | + } | ||
| 43 | + bench.end(len); | ||
| 44 | + break; | ||
| 31 | 45 | } | |
| 32 | - bench.end(len); | ||
| 33 | - } else if (arg === 'URL') { | ||
| 34 | - const options = data.map((i) => new URL(i)); | ||
| 35 | - bench.start(); | ||
| 36 | - for (i = 0; i < len; i++) { | ||
| 37 | - result = new ClientRequest(options[i], { createConnection: noop }); | ||
| 46 | + case 'string': { | ||
| 47 | + bench.start(); | ||
| 48 | + for (let i = 0; i < len; i++) { | ||
| 49 | + result = new ClientRequest(data[i], { createConnection: noop }); | ||
| 50 | + } | ||
| 51 | + bench.end(len); | ||
| 52 | + break; | ||
| 38 | 53 | } | |
| 39 | - bench.end(len); | ||
| 40 | - } else if (arg === 'string') { | ||
| 41 | - bench.start(); | ||
| 42 | - for (i = 0; i < len; i++) { | ||
| 43 | - result = new ClientRequest(data[i], { createConnection: noop }); | ||
| 54 | + default: { | ||
| 55 | + throw new Error(`Unknown arg type ${arg}`); | ||
| 44 | 56 | } | |
| 45 | - bench.end(len); | ||
| 46 | - } else { | ||
| 47 | - throw new Error(`Unknown arg type ${arg}`); | ||
| 48 | 57 | } | |
| 49 | - require('assert').ok(result); | ||
| 58 | + assert.ok(result); | ||
| 50 | 59 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,21 +4,20 @@ const common = require('../common.js'); | |||
| 4 | 4 | const http = require('http'); | |
| 5 | 5 | ||
| 6 | 6 | const bench = common.createBenchmark(main, { | |
| 7 | - duplicates: [1, 100], | ||
| 8 | 7 | n: [10, 1000], | |
| 8 | + len: [1, 100], | ||
| 9 | 9 | }); | |
| 10 | 10 | ||
| 11 | - function main({ duplicates, n }) { | ||
| 11 | + function main({ len, n }) { | ||
| 12 | 12 | const headers = { | |
| 13 | 13 | 'Connection': 'keep-alive', | |
| 14 | 14 | 'Transfer-Encoding': 'chunked', | |
| 15 | 15 | }; | |
| 16 | 16 | ||
| 17 | - for (var i = 0; i < n / duplicates; i++) { | ||
| 18 | - headers[`foo${i}`] = []; | ||
| 19 | - for (var j = 0; j < duplicates; j++) { | ||
| 20 | - headers[`foo${i}`].push(`some header value ${i}`); | ||
| 21 | - } | ||
| 17 | + const Is = [ ...Array(n / len).keys() ]; | ||
| 18 | + const Js = [ ...Array(len).keys() ]; | ||
| 19 | + for (const i of Is) { | ||
| 20 | + headers[`foo${i}`] = Js.map(() => `some header value ${i}`); | ||
| 22 | 21 | } | |
| 23 | 22 | ||
| 24 | 23 | const server = http.createServer((req, res) => { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,10 +5,10 @@ const http = require('http'); | |||
| 5 | 5 | const bench = common.createBenchmark(main, { | |
| 6 | 6 | // unicode confuses ab on os x. | |
| 7 | 7 | c: [50, 500], | |
| 8 | - headerDuplicates: [0, 5, 20] | ||
| 8 | + n: [0, 5, 20] | ||
| 9 | 9 | }); | |
| 10 | 10 | ||
| 11 | - function main({ c, headerDuplicates }) { | ||
| 11 | + function main({ c, n }) { | ||
| 12 | 12 | const server = http.createServer((req, res) => { | |
| 13 | 13 | res.end(); | |
| 14 | 14 | }); | |
@@ -21,7 +21,7 @@ function main({ c, headerDuplicates }) { | |||
| 21 | 21 | 'Date': new Date().toString(), | |
| 22 | 22 | 'Cache-Control': 'no-cache' | |
| 23 | 23 | }; | |
| 24 | - for (let i = 0; i < headerDuplicates; i++) { | ||
| 24 | + for (let i = 0; i < n; i++) { | ||
| 25 | 25 | headers[`foo${i}`] = `some header value ${i}`; | |
| 26 | 26 | } | |
| 27 | 27 | bench.http({ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,23 +14,21 @@ const runBenchmark = require('../common/benchmark'); | |||
| 14 | 14 | runBenchmark('http', | |
| 15 | 15 | [ | |
| 16 | 16 | 'benchmarker=test-double-http', | |
| 17 | - 'c=1', | ||
| 18 | - 'e=0', | ||
| 19 | - 'url=long', | ||
| 20 | 17 | 'arg=string', | |
| 18 | + 'c=1', | ||
| 21 | 19 | 'chunkedEnc=true', | |
| 22 | 20 | 'chunks=0', | |
| 23 | 21 | 'dur=0.1', | |
| 24 | - 'duplicates=1', | ||
| 22 | + 'e=0', | ||
| 25 | 23 | 'input=keep-alive', | |
| 26 | 24 | 'key=""', | |
| 27 | 25 | 'len=1', | |
| 28 | 26 | 'method=write', | |
| 29 | 27 | 'n=1', | |
| 30 | 28 | 'res=normal', | |
| 31 | 29 | 'type=asc', | |
| 30 | + 'url=long', | ||
| 32 | 31 | 'value=X-Powered-By', | |
| 33 | - 'headerDuplicates=1', | ||
| 34 | 32 | ], | |
| 35 | 33 | { | |
| 36 | 34 | NODEJS_BENCHMARK_ZERO_ALLOWED: 1, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments