@@ -5,31 +5,31 @@ import * as Benchmark from 'benchmark';
5
5
import fetch from 'node-fetch' ;
6
6
import * as request from 'request' ;
7
7
import got from '../source/index' ;
8
- import Request , { kIsNormalizedAlready } from '../source/core/index' ;
9
-
10
- const { normalizeArguments} = Request ;
8
+ import Request from '../source/core/index' ;
9
+ import Options , { OptionsInit } from '../source/core/options' ;
11
10
12
11
// Configuration
13
12
const httpsAgent = new https . Agent ( {
14
13
keepAlive : true ,
15
14
rejectUnauthorized : false
16
15
} ) ;
17
16
18
- const url = new URL ( 'https://127.0.0.1:8080 ' ) ;
17
+ const url = new URL ( 'https://127.0.0.1:8081 ' ) ;
19
18
const urlString = url . toString ( ) ;
20
19
21
- const gotOptions = {
20
+ const gotOptions : OptionsInit & { isStream ?: true } = {
22
21
agent : {
23
22
https : httpsAgent
24
23
} ,
25
- https : {
24
+ httpsOptions : {
26
25
rejectUnauthorized : false
27
26
} ,
28
- retry : 0
27
+ retry : {
28
+ limit : 0
29
+ }
29
30
} ;
30
31
31
- const normalizedGotOptions = normalizeArguments ( url , gotOptions ) ;
32
- normalizedGotOptions [ kIsNormalizedAlready ] = true ;
32
+ const normalizedGotOptions = new Options ( url , gotOptions ) ;
33
33
34
34
const requestOptions = {
35
35
strictSSL : false ,
@@ -80,6 +80,7 @@ suite.add('got - promise', {
80
80
defer : true ,
81
81
fn : async ( deferred : { resolve : ( ) => void } ) => {
82
82
const stream = new Request ( url , gotOptions ) ;
83
+ void stream . flush ( ) ;
83
84
stream . resume ( ) . once ( 'end' , ( ) => {
84
85
deferred . resolve ( ) ;
85
86
} ) ;
@@ -88,6 +89,7 @@ suite.add('got - promise', {
88
89
defer : true ,
89
90
fn : async ( deferred : { resolve : ( ) => void } ) => {
90
91
const stream = new Request ( undefined as any , normalizedGotOptions ) ;
92
+ void stream . flush ( ) ;
91
93
stream . resume ( ) . once ( 'end' , ( ) => {
92
94
deferred . resolve ( ) ;
93
95
} ) ;
@@ -169,7 +171,8 @@ const internalBenchmark = (): void => {
169
171
const internalSuite = new Benchmark . Suite ( ) ;
170
172
internalSuite . add ( 'got - normalize options' , {
171
173
fn : ( ) => {
172
- normalizeArguments ( url , gotOptions ) ;
174
+ // eslint-disable-next-line no-new
175
+ new Options ( url , gotOptions ) ;
173
176
}
174
177
} ) . on ( 'cycle' , ( event : Benchmark . Event ) => {
175
178
console . log ( String ( event . target ) ) ;
@@ -179,17 +182,48 @@ const internalBenchmark = (): void => {
179
182
} ;
180
183
181
184
// Results (i7-7700k, CPU governor: performance):
185
+
186
+ // e9359d3fa0cb40324f2b84364408b3f9f7ff2cee (Rewrite Got #1051) - unknown Node.js version
187
+ // got - promise x 3,092 ops/sec ±5.25% (73 runs sampled)
188
+ // got - stream x 4,313 ops/sec ±5.61% (72 runs sampled)
189
+ // got - promise core x 6,756 ops/sec ±5.32% (80 runs sampled)
190
+ // got - stream core x 6,863 ops/sec ±4.68% (76 runs sampled)
191
+ // got - stream core - normalized options x 7,960 ops/sec ±3.83% (81 runs sampled)
192
+
193
+ // b927e2d028ecc023bf7eff2702ffb5c72016a85a (Fix bugs, increase coverage, update benchmark results) - unknown Node.js version
194
+ // got - promise x 3,204 ops/sec ±5.27% (73 runs sampled)
195
+ // got - stream x 5,045 ops/sec ±3.85% (77 runs sampled)
196
+ // got - promise core x 6,499 ops/sec ±3.67% (77 runs sampled)
197
+ // got - stream core x 7,047 ops/sec ±2.32% (83 runs sampled)
198
+ // got - stream core - normalized options x 7,313 ops/sec ±2.79% (85 runs sampled)
199
+
200
+ // 7e8898e9095e7da52e4ff342606cfd1dc5186f54 (Merge PromisableRequest into Request) - unknown Node.js version
182
201
// got - promise x 3,003 ops/sec ±6.26% (70 runs sampled)
183
202
// got - stream x 3,538 ops/sec ±5.86% (67 runs sampled)
184
203
// got - core x 5,828 ops/sec ±3.11% (79 runs sampled)
185
204
// got - core - normalized options x 7,596 ops/sec ±1.60% (85 runs sampled)
186
- // request - callback x 6,530 ops/sec ±6.84% (72 runs sampled)
187
- // request - stream x 7,348 ops/sec ±3.62% (78 runs sampled)
188
- // node-fetch - promise x 6,284 ops/sec ±5.50% (76 runs sampled)
189
- // node-fetch - stream x 7,746 ops/sec ±3.32% (80 runs sampled)
190
- // axios - promise x 6,301 ops/sec ±6.24% (77 runs sampled)
191
- // axios - stream x 8,605 ops/sec ±2.73% (87 runs sampled)
192
- // https - stream x 10,477 ops/sec ±3.64% (80 runs sampled)
193
- // Fastest is https - stream
194
205
195
- // got - normalize options x 90,974 ops/sec ±0.57% (93 runs sampled)
206
+ // [main] - Node.js v15.10.0
207
+ // got - promise x 3,201 ops/sec ±5.24% (67 runs sampled)
208
+ // got - stream x 3,633 ops/sec ±4.06% (74 runs sampled)
209
+ // got - core x 4,382 ops/sec ±3.26% (77 runs sampled)
210
+ // got - core - normalized options x 5,470 ops/sec ±3.70% (78 runs sampled)
211
+
212
+ // v12 - Node.js v15.10.0
213
+ // got - promise x 3,492 ops/sec ±5.13% (71 runs sampled)
214
+ // got - stream x 4,772 ops/sec ±1.52% (84 runs sampled)
215
+ // got - core x 4,990 ops/sec ±1.14% (83 runs sampled)
216
+ // got - core - normalized options x 5,386 ops/sec ±0.52% (87 runs sampled)
217
+
218
+ // got - normalize options x 117,810 ops/sec ±0.36% (97 runs sampled)
219
+
220
+ // ================================================================================
221
+
222
+ // request - callback x 6,448 ops/sec ±5.76% (67 runs sampled)
223
+ // request - stream x 7,115 ops/sec ±2.85% (83 runs sampled)
224
+ // node-fetch - promise x 6,236 ops/sec ±5.56% (75 runs sampled)
225
+ // node-fetch - stream x 7,225 ops/sec ±2.10% (81 runs sampled)
226
+ // axios - promise x 5,620 ops/sec ±3.13% (78 runs sampled)
227
+ // axios - stream x 7,244 ops/sec ±3.31% (80 runs sampled)
228
+ // https - stream x 8,588 ops/sec ±5.50% (61 runs sampled)
229
+ // Fastest is https - stream
0 commit comments