Skip to content

Commit 5ec393e

Browse files
mohawk2leebyron
authored andcommitted
Benchmark introspecting a schema built from SDL in a supplied file. (#1163)
* Benchmark introspecting a schema built from SDL in a supplied file. Use it like so: ```shell yarn run benchmark ```` Additionally there is a profile command which runs the benchmark with `--prof`: ```shell yarn run profile ```` Note that on Ubuntu 16.04 this requires: ```shell sudo apt install linux-tools-common gawk linux-tools-generic linux-tools-4.10.0-35-generic sudo sh -c 'echo 1 >/proc/sys/kernel/perf_event_paranoid' ``` On my laptop it produces this: ``` $ yarn run benchmark > [email protected] benchmark /home/osboxes/graphql-js > babel-node ./resources/benchmark/run.js introspectionQuery x 24.59 ops/sec ±3.87% (45 runs sampled) ``` * Move into benchmark tests
1 parent 8151240 commit 5ec393e

6 files changed

+48158
-2
lines changed

resources/benchmark.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function prepareRevision(revision) {
5353
(cd "${dir}" && yarn install);
5454
fi &&
5555
# Copy in local tests so the same logic applies to each revision.
56-
for file in $(cd "${LOCAL_DIR}src"; find . -path '*/__tests__/*.js');
56+
for file in $(cd "${LOCAL_DIR}src"; find . -path '*/__tests__/*');
5757
do cp "${LOCAL_DIR}src/$file" "${dir}/src/$file";
5858
done &&
5959
(cd "${dir}" && yarn run ${BUILD_CMD})
@@ -82,18 +82,22 @@ function runBenchmark(benchmark, revisions) {
8282
const suite = new Suite(modules[0].name, {
8383
onStart(event) {
8484
console.log('⏱️ ' + event.currentTarget.name);
85+
beautifyBenchmark.reset();
8586
},
8687
onCycle(event) {
8788
beautifyBenchmark.add(event.target);
8889
},
90+
onError(event) {
91+
console.error(event.target.error);
92+
},
8993
onComplete() {
9094
beautifyBenchmark.log();
9195
},
9296
});
9397
for (let i = 0; i < revisions.length; i++) {
9498
suite.add(revisions[i], modules[i].measure);
9599
}
96-
suite.run();
100+
suite.run({ async: false });
97101
}
98102

99103
// Prepare all revisions and run benchmarks matching a pattern against them.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
import { join } from 'path';
9+
import { readFileSync } from 'fs';
10+
import { parse } from '../../';
11+
import { buildASTSchema } from '../buildASTSchema';
12+
13+
const schemaAST = parse(
14+
readFileSync(join(__dirname, 'github-schema.graphql'), 'utf8'),
15+
);
16+
17+
export const name = 'Build Schema from AST';
18+
export function measure() {
19+
buildASTSchema(schemaAST);
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
import { join } from 'path';
9+
import { readFileSync } from 'fs';
10+
import { buildClientSchema } from '../buildClientSchema';
11+
12+
const schemaJSON = JSON.parse(
13+
readFileSync(join(__dirname, 'github-schema.json'), 'utf8'),
14+
);
15+
16+
export const name = 'Build Schema from Introspection';
17+
export function measure() {
18+
buildClientSchema(schemaJSON.data);
19+
}

0 commit comments

Comments
 (0)