Skip to content

Commit

Permalink
Benchmark introspecting a schema built from SDL in a supplied file. (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
mohawk2 authored and leebyron committed Feb 20, 2018
1 parent 8151240 commit 5ec393e
Show file tree
Hide file tree
Showing 6 changed files with 48,158 additions and 2 deletions.
8 changes: 6 additions & 2 deletions resources/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function prepareRevision(revision) {
(cd "${dir}" && yarn install);
fi &&
# Copy in local tests so the same logic applies to each revision.
for file in $(cd "${LOCAL_DIR}src"; find . -path '*/__tests__/*.js');
for file in $(cd "${LOCAL_DIR}src"; find . -path '*/__tests__/*');
do cp "${LOCAL_DIR}src/$file" "${dir}/src/$file";
done &&
(cd "${dir}" && yarn run ${BUILD_CMD})
Expand Down Expand Up @@ -82,18 +82,22 @@ function runBenchmark(benchmark, revisions) {
const suite = new Suite(modules[0].name, {
onStart(event) {
console.log('⏱️ ' + event.currentTarget.name);
beautifyBenchmark.reset();
},
onCycle(event) {
beautifyBenchmark.add(event.target);
},
onError(event) {
console.error(event.target.error);
},
onComplete() {
beautifyBenchmark.log();
},
});
for (let i = 0; i < revisions.length; i++) {
suite.add(revisions[i], modules[i].measure);
}
suite.run();
suite.run({ async: false });
}

// Prepare all revisions and run benchmarks matching a pattern against them.
Expand Down
20 changes: 20 additions & 0 deletions src/utilities/__tests__/buildASTSchema-benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import { join } from 'path';
import { readFileSync } from 'fs';
import { parse } from '../../';
import { buildASTSchema } from '../buildASTSchema';

const schemaAST = parse(
readFileSync(join(__dirname, 'github-schema.graphql'), 'utf8'),
);

export const name = 'Build Schema from AST';
export function measure() {
buildASTSchema(schemaAST);
}
19 changes: 19 additions & 0 deletions src/utilities/__tests__/buildClientSchema-benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import { join } from 'path';
import { readFileSync } from 'fs';
import { buildClientSchema } from '../buildClientSchema';

const schemaJSON = JSON.parse(
readFileSync(join(__dirname, 'github-schema.json'), 'utf8'),
);

export const name = 'Build Schema from Introspection';
export function measure() {
buildClientSchema(schemaJSON.data);
}
Loading

0 comments on commit 5ec393e

Please sign in to comment.