Skip to content

Async benchmarks #3134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions benchmark/list-async-benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { execute } from 'graphql/execution/execute.js';
import { parse } from 'graphql/language/parser.js';
import { buildSchema } from 'graphql/utilities/buildASTSchema.js';

const schema = buildSchema('type Query { listField: [String] }');
const document = parse('{ listField }');

function listField() {
const results = [];
for (let index = 0; index < 1000; index++) {
results.push(Promise.resolve(index));
}
return results;
}

export const benchmark = {
name: 'Execute Asynchronous List Field',
count: 10,
async measure() {
await execute({
schema,
document,
rootValue: { listField },
});
},
};
26 changes: 26 additions & 0 deletions benchmark/list-sync-benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { execute } from 'graphql/execution/execute.js';
import { parse } from 'graphql/language/parser.js';
import { buildSchema } from 'graphql/utilities/buildASTSchema.js';

const schema = buildSchema('type Query { listField: [String] }');
const document = parse('{ listField }');

function listField() {
const results = [];
for (let index = 0; index < 1000; index++) {
results.push(index);
}
return results;
}

export const benchmark = {
name: 'Execute Synchronous List Field',
count: 10,
async measure() {
await execute({
schema,
document,
rootValue: { listField },
});
},
};
16 changes: 8 additions & 8 deletions resources/benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,20 +385,20 @@ function sampleModule(modulePath: string): BenchmarkSample {
import { benchmark } from '${moduleURL}';

// warm up, it looks like 7 is a magic number to reliably trigger JIT
benchmark.measure();
benchmark.measure();
benchmark.measure();
benchmark.measure();
benchmark.measure();
benchmark.measure();
benchmark.measure();
await benchmark.measure();
await benchmark.measure();
await benchmark.measure();
await benchmark.measure();
await benchmark.measure();
await benchmark.measure();
await benchmark.measure();

const memBaseline = process.memoryUsage().heapUsed;

const resourcesStart = process.resourceUsage();
const startTime = process.hrtime.bigint();
for (let i = 0; i < benchmark.count; ++i) {
benchmark.measure();
await benchmark.measure();
}
const timeDiff = Number(process.hrtime.bigint() - startTime);
const resourcesEnd = process.resourceUsage();
Expand Down