Skip to content

Commit f52d76f

Browse files
committed
Add benchmarks for sync and async list fields
1 parent 57937b9 commit f52d76f

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

benchmark/list-async-benchmark.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
};

benchmark/list-sync-benchmark.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
};

0 commit comments

Comments
 (0)