Skip to content

Commit

Permalink
Merge "large" benchmarks with "array" and update results
Browse files Browse the repository at this point in the history
  • Loading branch information
MichalLytek committed Dec 28, 2019
1 parent 2b044b3 commit ac6548a
Show file tree
Hide file tree
Showing 14 changed files with 206 additions and 204 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,34 @@ import {
GraphQLList,
} from "graphql";

import { runBenchmark, ARRAY_ITEMS } from "./run";
import { runBenchmark, ARRAY_ITEMS } from "../run";

const SampleObjectType: GraphQLObjectType = new GraphQLObjectType({
name: "SampleObject",
fields: () => ({
sampleField: {
type: new GraphQLNonNull(GraphQLString),
resolve: (source) => {
resolve: async source => {
return source.sampleField;
}
},
},
numberField: {
type: new GraphQLNonNull(GraphQLInt),
resolve: (source) => {
resolve: async source => {
return source.numberField;
}
},
},
booleanField: {
type: new GraphQLNonNull(GraphQLBoolean),
resolve: (source) => {
resolve: async source => {
return source.booleanField;
}
},
},
nestedField: {
type: SampleObjectType,
resolve: (source) => {
resolve: async source => {
return source.nestedField;
}
},
},
}),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
GraphQLList,
} from "graphql";

import { runBenchmark, ARRAY_ITEMS } from "./run";
import { runBenchmark, ARRAY_ITEMS } from "../run";

const SampleObjectType: GraphQLObjectType = new GraphQLObjectType({
name: "SampleObject",
Expand Down
31 changes: 25 additions & 6 deletions benchmarks/array/results.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
Core i7 2700K @ 3.5GHz
Windows 10 x64
10 000 array items | 100 iterations
25 000 array items | 50 iterations
Node.js v13.5

-----
Node.js v13.2
TypeGraphQL

standard
- 42.551s
- 15.518s

using sync field resolvers
- 18.180s

using async field resolvers
- 39.934s

using getters
- 31.207s

standard with global middleware
- 62.664s

with `simpleResolvers: true`
- 11.841s
- 14.980s

-----
`graphql-js`

standard
- 13.276s

graphql-js
- 9.963s
async field resolvers
- 25.630s
4 changes: 2 additions & 2 deletions benchmarks/array/run.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { GraphQLSchema, execute } from "graphql";
import { gql } from "apollo-server";

const BENCHMARK_ITERATIONS = 100;
export const ARRAY_ITEMS = 10000;
const BENCHMARK_ITERATIONS = 50;
export const ARRAY_ITEMS = 25000;

export async function runBenchmark(schema: GraphQLSchema) {
const multipleNestedObjectsQuery = gql`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import "reflect-metadata";
import { buildSchema, Field, ObjectType, Resolver, Query, Int, FieldResolver, Root } from "../../build/package";
import {
buildSchema,
Field,
ObjectType,
Resolver,
Query,
Int,
FieldResolver,
Root,
} from "../../../build/package/dist";

import { runBenchmark, ARRAY_ITEMS } from "./run";
import { runBenchmark, ARRAY_ITEMS } from "../run";

@ObjectType()
class SampleObject {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import "reflect-metadata";
import { buildSchema, Field, ObjectType, Resolver, Query, Int } from "../../build/package";
import {
buildSchema,
Field,
ObjectType,
Resolver,
Query,
Int,
MiddlewareFn,
} from "../../../build/package/dist";

import { runBenchmark, ARRAY_ITEMS } from "./run";
import { runBenchmark, ARRAY_ITEMS } from "../run";

@ObjectType({ simpleResolvers: true })
class SampleObject {
Expand Down Expand Up @@ -38,9 +46,17 @@ class SampleResolver {
}
}

const log = (...args: any[]) => void 0; // noop

const loggingMiddleware: MiddlewareFn = ({ info }, next) => {
log(`${info.parentType.name}.${info.fieldName} accessed`);
return next();
};

async function main() {
const schema = await buildSchema({
resolvers: [SampleResolver],
globalMiddlewares: [loggingMiddleware],
});

await runBenchmark(schema);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "reflect-metadata";
import { buildSchema, Field, ObjectType, Resolver, Query, Int } from "../../build/package";
import { buildSchema, Field, ObjectType, Resolver, Query, Int } from "../../../build/package/dist";

import { runBenchmark, ARRAY_ITEMS } from "./run";
import { runBenchmark, ARRAY_ITEMS } from "../run";

@ObjectType()
class SampleObject {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import "reflect-metadata";
import { buildSchema, Field, ObjectType, Resolver, Query, Int, FieldResolver, Root } from "../../build/package";
import {
buildSchema,
Field,
ObjectType,
Resolver,
Query,
Int,
FieldResolver,
Root,
} from "../../../build/package/dist";

import { runBenchmark, ARRAY_ITEMS } from "./run";
import { runBenchmark, ARRAY_ITEMS } from "../../large/run";

@ObjectType()
class SampleObject {
Expand Down
62 changes: 62 additions & 0 deletions benchmarks/array/type-graphql/sync-getters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import "reflect-metadata";
import { buildSchema, Field, ObjectType, Resolver, Query, Int } from "../../../build/package/dist";

import { runBenchmark, ARRAY_ITEMS } from "../../large/run";

@ObjectType()
class SampleObject {
stringField!: string;
@Field({ name: "stringField" })
get getStringField(): string {
return this.stringField;
}

numberField!: number;
@Field(type => Int, { name: "numberField" })
get getNumberField(): number {
return this.numberField;
}

booleanField!: boolean;
@Field({ name: "booleanField" })
get getBooleanField(): boolean {
return this.booleanField;
}

nestedField?: SampleObject;
@Field(type => SampleObject, { name: "nestedField", nullable: true })
get getNestedField(): SampleObject | undefined {
return this.nestedField;
}
}

@Resolver(SampleObject)
class SampleResolver {
@Query(returns => [SampleObject])
multipleNestedObjects(): SampleObject[] {
return Array.from(
{ length: ARRAY_ITEMS },
(_, index): SampleObject =>
({
stringField: "stringField",
booleanField: true,
numberField: index,
nestedField: {
stringField: "stringField",
booleanField: true,
numberField: index,
} as SampleObject,
} as SampleObject),
);
}
}

async function main() {
const schema = await buildSchema({
resolvers: [SampleResolver],
});

await runBenchmark(schema);
}

main().catch(console.error);
65 changes: 65 additions & 0 deletions benchmarks/array/type-graphql/with-global-middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import "reflect-metadata";
import {
buildSchema,
Field,
ObjectType,
Resolver,
Query,
Int,
MiddlewareFn,
} from "../../../build/package/dist";

import { runBenchmark, ARRAY_ITEMS } from "../run";

@ObjectType()
class SampleObject {
@Field()
stringField!: string;

@Field(type => Int)
numberField!: number;

@Field()
booleanField!: boolean;

@Field({ nullable: true })
nestedField?: SampleObject;
}

@Resolver()
class SampleResolver {
@Query(returns => [SampleObject])
multipleNestedObjects(): SampleObject[] {
return Array.from(
{ length: ARRAY_ITEMS },
(_, index): SampleObject => ({
stringField: "stringField",
booleanField: true,
numberField: index,
nestedField: {
stringField: "stringField",
booleanField: true,
numberField: index,
},
}),
);
}
}

const log = (...args: any[]) => void 0; // noop

const loggingMiddleware: MiddlewareFn = ({ info }, next) => {
log(`${info.parentType.name}.${info.fieldName} accessed`);
return next();
};

async function main() {
const schema = await buildSchema({
resolvers: [SampleResolver],
globalMiddlewares: [loggingMiddleware],
});

await runBenchmark(schema);
}

main().catch(console.error);
65 changes: 0 additions & 65 deletions benchmarks/large/raw-async.ts

This file was deleted.

Loading

0 comments on commit ac6548a

Please sign in to comment.