File tree Expand file tree Collapse file tree 3 files changed +60
-8
lines changed Expand file tree Collapse file tree 3 files changed +60
-8
lines changed Original file line number Diff line number Diff line change 1+ import { execute } from 'graphql/execution/execute.js' ;
2+ import { parse } from 'graphql/language/parser.js' ;
3+ import { buildSchema } from 'graphql/utilities/buildASTSchema.js' ;
4+
5+ const schema = buildSchema ( 'type Query { listField: [String] }' ) ;
6+ const document = parse ( '{ listField }' ) ;
7+
8+ function listField ( ) {
9+ const results = [ ] ;
10+ for ( let index = 0 ; index < 1000 ; index ++ ) {
11+ results . push ( Promise . resolve ( index ) ) ;
12+ }
13+ return results ;
14+ }
15+
16+ export const benchmark = {
17+ name : 'Execute Asynchronous List Field' ,
18+ count : 10 ,
19+ async measure ( ) {
20+ await execute ( {
21+ schema,
22+ document,
23+ rootValue : { listField } ,
24+ } ) ;
25+ } ,
26+ } ;
Original file line number Diff line number Diff line change 1+ import { execute } from 'graphql/execution/execute.js' ;
2+ import { parse } from 'graphql/language/parser.js' ;
3+ import { buildSchema } from 'graphql/utilities/buildASTSchema.js' ;
4+
5+ const schema = buildSchema ( 'type Query { listField: [String] }' ) ;
6+ const document = parse ( '{ listField }' ) ;
7+
8+ function listField ( ) {
9+ const results = [ ] ;
10+ for ( let index = 0 ; index < 1000 ; index ++ ) {
11+ results . push ( index ) ;
12+ }
13+ return results ;
14+ }
15+
16+ export const benchmark = {
17+ name : 'Execute Synchronous List Field' ,
18+ count : 10 ,
19+ async measure ( ) {
20+ await execute ( {
21+ schema,
22+ document,
23+ rootValue : { listField } ,
24+ } ) ;
25+ } ,
26+ } ;
Original file line number Diff line number Diff line change @@ -385,20 +385,20 @@ function sampleModule(modulePath: string): BenchmarkSample {
385385 import { benchmark } from '${ moduleURL } ';
386386
387387 // warm up, it looks like 7 is a magic number to reliably trigger JIT
388- benchmark.measure();
389- benchmark.measure();
390- benchmark.measure();
391- benchmark.measure();
392- benchmark.measure();
393- benchmark.measure();
394- benchmark.measure();
388+ await benchmark.measure();
389+ await benchmark.measure();
390+ await benchmark.measure();
391+ await benchmark.measure();
392+ await benchmark.measure();
393+ await benchmark.measure();
394+ await benchmark.measure();
395395
396396 const memBaseline = process.memoryUsage().heapUsed;
397397
398398 const resourcesStart = process.resourceUsage();
399399 const startTime = process.hrtime.bigint();
400400 for (let i = 0; i < benchmark.count; ++i) {
401- benchmark.measure();
401+ await benchmark.measure();
402402 }
403403 const timeDiff = Number(process.hrtime.bigint() - startTime);
404404 const resourcesEnd = process.resourceUsage();
You can’t perform that action at this time.
0 commit comments