diff --git a/benchmark/object-async-benchmark.js b/benchmark/object-async-benchmark.js new file mode 100644 index 0000000000..ed5e178ee9 --- /dev/null +++ b/benchmark/object-async-benchmark.js @@ -0,0 +1,32 @@ +import { execute } from 'graphql/execution/execute.js'; +import { parse } from 'graphql/language/parser.js'; +import { buildSchema } from 'graphql/utilities/buildASTSchema.js'; + +const fieldCount = 1000; +const fieldNames = Array.from( + { length: fieldCount }, + (_, index) => `f${index}`, +); + +const schema = buildSchema( + `type Query { ${fieldNames.map((fieldName) => `${fieldName}: Int`).join(' ')} }`, +); + +const document = parse(`{ ${fieldNames.join(' ')} }`); + +const rootValue = Object.fromEntries( + fieldNames.map((fieldName, index) => [ + fieldName, + () => Promise.resolve(index), + ]), +); + +export const benchmark = { + name: 'Execute Asynchronous Fields', + measure: () => + execute({ + schema, + document, + rootValue, + }), +};