Skip to content

Commit

Permalink
Got 12 improvements (#1667)
Browse files Browse the repository at this point in the history
  • Loading branch information
szmarczak authored Apr 11, 2021
1 parent 4cce4de commit 3c23eea
Show file tree
Hide file tree
Showing 50 changed files with 4,106 additions and 3,814 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ yarn.lock
coverage
.nyc_output
dist
*.0x
72 changes: 53 additions & 19 deletions benchmark/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,31 @@ import * as Benchmark from 'benchmark';
import fetch from 'node-fetch';
import * as request from 'request';
import got from '../source/index';
import Request, {kIsNormalizedAlready} from '../source/core/index';

const {normalizeArguments} = Request;
import Request from '../source/core/index';
import Options, {OptionsInit} from '../source/core/options';

// Configuration
const httpsAgent = new https.Agent({
keepAlive: true,
rejectUnauthorized: false
});

const url = new URL('https://127.0.0.1:8080');
const url = new URL('https://127.0.0.1:8081');
const urlString = url.toString();

const gotOptions = {
const gotOptions: OptionsInit & {isStream?: true} = {
agent: {
https: httpsAgent
},
https: {
httpsOptions: {
rejectUnauthorized: false
},
retry: 0
retry: {
limit: 0
}
};

const normalizedGotOptions = normalizeArguments(url, gotOptions);
normalizedGotOptions[kIsNormalizedAlready] = true;
const normalizedGotOptions = new Options(url, gotOptions);

const requestOptions = {
strictSSL: false,
Expand Down Expand Up @@ -80,6 +80,7 @@ suite.add('got - promise', {
defer: true,
fn: async (deferred: {resolve: () => void}) => {
const stream = new Request(url, gotOptions);
void stream.flush();
stream.resume().once('end', () => {
deferred.resolve();
});
Expand All @@ -88,6 +89,7 @@ suite.add('got - promise', {
defer: true,
fn: async (deferred: {resolve: () => void}) => {
const stream = new Request(undefined as any, normalizedGotOptions);
void stream.flush();
stream.resume().once('end', () => {
deferred.resolve();
});
Expand Down Expand Up @@ -169,7 +171,8 @@ const internalBenchmark = (): void => {
const internalSuite = new Benchmark.Suite();
internalSuite.add('got - normalize options', {
fn: () => {
normalizeArguments(url, gotOptions);
// eslint-disable-next-line no-new
new Options(url, gotOptions);
}
}).on('cycle', (event: Benchmark.Event) => {
console.log(String(event.target));
Expand All @@ -179,17 +182,48 @@ const internalBenchmark = (): void => {
};

// Results (i7-7700k, CPU governor: performance):

// e9359d3fa0cb40324f2b84364408b3f9f7ff2cee (Rewrite Got #1051) - unknown Node.js version
// got - promise x 3,092 ops/sec ±5.25% (73 runs sampled)
// got - stream x 4,313 ops/sec ±5.61% (72 runs sampled)
// got - promise core x 6,756 ops/sec ±5.32% (80 runs sampled)
// got - stream core x 6,863 ops/sec ±4.68% (76 runs sampled)
// got - stream core - normalized options x 7,960 ops/sec ±3.83% (81 runs sampled)

// b927e2d028ecc023bf7eff2702ffb5c72016a85a (Fix bugs, increase coverage, update benchmark results) - unknown Node.js version
// got - promise x 3,204 ops/sec ±5.27% (73 runs sampled)
// got - stream x 5,045 ops/sec ±3.85% (77 runs sampled)
// got - promise core x 6,499 ops/sec ±3.67% (77 runs sampled)
// got - stream core x 7,047 ops/sec ±2.32% (83 runs sampled)
// got - stream core - normalized options x 7,313 ops/sec ±2.79% (85 runs sampled)

// 7e8898e9095e7da52e4ff342606cfd1dc5186f54 (Merge PromisableRequest into Request) - unknown Node.js version
// got - promise x 3,003 ops/sec ±6.26% (70 runs sampled)
// got - stream x 3,538 ops/sec ±5.86% (67 runs sampled)
// got - core x 5,828 ops/sec ±3.11% (79 runs sampled)
// got - core - normalized options x 7,596 ops/sec ±1.60% (85 runs sampled)
// request - callback x 6,530 ops/sec ±6.84% (72 runs sampled)
// request - stream x 7,348 ops/sec ±3.62% (78 runs sampled)
// node-fetch - promise x 6,284 ops/sec ±5.50% (76 runs sampled)
// node-fetch - stream x 7,746 ops/sec ±3.32% (80 runs sampled)
// axios - promise x 6,301 ops/sec ±6.24% (77 runs sampled)
// axios - stream x 8,605 ops/sec ±2.73% (87 runs sampled)
// https - stream x 10,477 ops/sec ±3.64% (80 runs sampled)
// Fastest is https - stream

// got - normalize options x 90,974 ops/sec ±0.57% (93 runs sampled)
// [main] - Node.js v15.10.0
// got - promise x 3,201 ops/sec ±5.24% (67 runs sampled)
// got - stream x 3,633 ops/sec ±4.06% (74 runs sampled)
// got - core x 4,382 ops/sec ±3.26% (77 runs sampled)
// got - core - normalized options x 5,470 ops/sec ±3.70% (78 runs sampled)

// v12 - Node.js v15.10.0
// got - promise x 3,492 ops/sec ±5.13% (71 runs sampled)
// got - stream x 4,772 ops/sec ±1.52% (84 runs sampled)
// got - core x 4,990 ops/sec ±1.14% (83 runs sampled)
// got - core - normalized options x 5,386 ops/sec ±0.52% (87 runs sampled)

// got - normalize options x 117,810 ops/sec ±0.36% (97 runs sampled)

// ================================================================================

// request - callback x 6,448 ops/sec ±5.76% (67 runs sampled)
// request - stream x 7,115 ops/sec ±2.85% (83 runs sampled)
// node-fetch - promise x 6,236 ops/sec ±5.56% (75 runs sampled)
// node-fetch - stream x 7,225 ops/sec ±2.10% (81 runs sampled)
// axios - promise x 5,620 ops/sec ±3.13% (78 runs sampled)
// axios - stream x 7,244 ops/sec ±3.31% (80 runs sampled)
// https - stream x 8,588 ops/sec ±5.50% (61 runs sampled)
// Fastest is https - stream
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
"cacheable-lookup": "^6.0.0",
"cacheable-request": "^7.0.1",
"decompress-response": "^6.0.0",
"http2-wrapper": "^2.0.0",
"get-stream": "^6.0.0",
"http2-wrapper": "^2.0.1",
"lowercase-keys": "^2.0.0",
"p-cancelable": "^2.0.0",
"responselike": "^2.0.0"
Expand Down Expand Up @@ -78,7 +79,6 @@
"delay": "^5.0.0",
"express": "^4.17.1",
"form-data": "^4.0.0",
"get-stream": "^6.0.0",
"nock": "^13.0.7",
"node-fetch": "^2.6.1",
"np": "^7.4.0",
Expand Down Expand Up @@ -137,7 +137,8 @@
"import/no-anonymous-default-export": "off",
"@typescript-eslint/no-implicit-any-catch": "off",
"unicorn/import-index": "off",
"import/no-useless-path-segments": "off"
"import/no-useless-path-segments": "off",
"import/no-named-as-default": "off"
}
},
"runkitExampleFilename": "./documentation/examples/runkit-example.js"
Expand Down
31 changes: 0 additions & 31 deletions source/as-promise/create-rejection.ts

This file was deleted.

Loading

0 comments on commit 3c23eea

Please sign in to comment.