Skip to content

Commit a55916f

Browse files
committed
Add benchmarks for sync and async list fields
1 parent 371223f commit a55916f

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

benchmark/list-async-benchmark.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict';
2+
3+
const { parse } = require('graphql/language/parser.js');
4+
const { execute } = require('graphql/execution/execute.js');
5+
const { buildSchema } = require('graphql/utilities/buildASTSchema.js');
6+
7+
const schema = buildSchema('type Query { listField: [String] }');
8+
const document = parse('{ listField }');
9+
10+
function listField() {
11+
const results = [];
12+
for (let index = 0; index < 100000; index++) {
13+
results.push(Promise.resolve(index));
14+
}
15+
return results;
16+
}
17+
18+
module.exports = {
19+
name: 'Execute Asynchronous List Field',
20+
count: 10,
21+
async measure() {
22+
await execute({
23+
schema,
24+
document,
25+
rootValue: { listField },
26+
});
27+
},
28+
};

benchmark/list-sync-benchmark.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict';
2+
3+
const { parse } = require('graphql/language/parser.js');
4+
const { execute } = require('graphql/execution/execute.js');
5+
const { buildSchema } = require('graphql/utilities/buildASTSchema.js');
6+
7+
const schema = buildSchema('type Query { listField: [String] }');
8+
const document = parse('{ listField }');
9+
10+
function listField() {
11+
const results = [];
12+
for (let index = 0; index < 100000; index++) {
13+
results.push(index);
14+
}
15+
return results;
16+
}
17+
18+
module.exports = {
19+
name: 'Execute Synchronous List Field',
20+
count: 10,
21+
async measure() {
22+
await execute({
23+
schema,
24+
document,
25+
rootValue: { listField },
26+
});
27+
},
28+
};

0 commit comments

Comments
 (0)