Git Product home page Git Product logo

rest-vs-graphql-bench's Introduction

Bench REST vs GraphQL

Getting started

Install dependencies

yarn

Make sure have mongo database setup

Start an instance of mongodb

docker run -d --name mongo -p 27017:27017 mongo:4

Install autocannon for bench:

npm install -g autocannon

Setup test data

`yarn bin`/ts-node src/create-test-data.ts

Bench

Build production: yarn build Start app: yarn start

REST

autocannon -t 10 -c 400 -d 15s http://localhost:3000/posts
Stat 1% 2.5% 50% 97.5% Avg Stdev Min
Req/Sec 541 541 600 612 594.74 15.98 541
Bytes/Sec 61.6 MB 61.6 MB 68.4 MB 69.7 MB 67.7 MB 1.82 MB 61.6 MB

GraphQL

autocannon -t 10 -c 400 -d 15s -m POST -H content-type='application/json' -b '{ "query": "{ posts { title description body tags } }" }' http://localhost:3000/graphql
Stat 1% 2.5% 50% 97.5% Avg Stdev Min
Req/Sec 375 375 482 510 478.34 29.96 375
Bytes/Sec 38.3 MB 38.3 MB 49.2 MB 52 MB 48.8 MB 3.06 MB 38.3 MB

Result

REST is 124% faster than GraphQL (594 req/s vs 478/s)

TODO

  • Add persisted query with redis cache
  • Add koa tests
  • Add fastify tests

rest-vs-graphql-bench's People

Contributors

joehua87 avatar

Stargazers

Roman avatar Hieu Lam avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.