diff --git a/.circleci/config.yml b/.circleci/config.yml index 474727fef9fe5..b267144509cfc 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -402,8 +402,27 @@ jobs: paths: - "*" + run_benchmarks: + docker: + - image: circleci/node:12 + resource_class: xlarge + steps: + - checkout + - run: ./scripts/build-benchmark.sh + workflows: version: 2 + + run_benchmarks: + jobs: [run_benchmarks] + triggers: + - schedule: + cron: "12 3 * * *" # every day at 03:12 + filters: + branches: + only: + - master + nightly-react-next: triggers: - schedule: diff --git a/benchmarks/README.md b/benchmarks/README.md new file mode 100644 index 0000000000000..adcf627ce7f0e --- /dev/null +++ b/benchmarks/README.md @@ -0,0 +1,24 @@ +# Benchmarks + +Example sites for benchmarking `gatsby`. + +## Interface + +The standard interface for running a benchmark is: + +``` +cd {benchmark directory} +export NUM_PAGES={n} +npm install +gatsby build +``` + +If a specific benchmark needs to perform some code generation (e.g. `markdown_id`), +that generation shall happen in a `postinstall` script. +Any `postinstall` script must ensure that previous benchmark runs do not interfere with the current run. + +For example: + +``` +"postinstall": "del-cli ./generated && gatsby clean && npm run generate" +``` diff --git a/benchmarks/markdown_id/package.json b/benchmarks/markdown_id/package.json index ca02134423c8b..850252a5b29d0 100644 --- a/benchmarks/markdown_id/package.json +++ b/benchmarks/markdown_id/package.json @@ -5,6 +5,7 @@ "version": "0.0.1", "author": "PvdZ ", "dependencies": { + "del-cli": "^3.0.0", "gatsby": "*", "gatsby-image": "*", "gatsby-plugin-feed": "*", @@ -51,6 +52,6 @@ "test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\" && exit 1", "bench": "rm -r markdown-pages; NUM_PAGES=${NUM_PAGES:-2000} node md.generate.js; gatsby clean; node --max_old_space_size=2000 node_modules/.bin/gatsby build", "benchnb": "gatsby clean; node --max_old_space_size=2000 node_modules/.bin/gatsby build", - "postinstall": "NUM_PAGES=${NUM_PAGES:-2000} node md.generate.js" + "postinstall": "del-cli markdown-pages && gatsby clean && NUM_PAGES=${NUM_PAGES:-2000} node md.generate.js" } } diff --git a/benchmarks/markdown_slug/package.json b/benchmarks/markdown_slug/package.json index f5e2bc2b7c127..0e99b0f87aaa3 100644 --- a/benchmarks/markdown_slug/package.json +++ b/benchmarks/markdown_slug/package.json @@ -5,6 +5,7 @@ "version": "0.0.1", "author": "PvdZ ", "dependencies": { + "del-cli": "^3.0.0", "gatsby": "*", "gatsby-image": "*", "gatsby-plugin-feed": "*", @@ -51,6 +52,6 @@ "test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\" && exit 1", "bench": "rm -r markdown-pages; NUM_PAGES=${NUM_PAGES:-2000} node md.generate.js; gatsby clean; node --max_old_space_size=2000 node_modules/.bin/gatsby build", "benchnb": "gatsby clean; node --max_old_space_size=2000 node_modules/.bin/gatsby build", - "postinstall": "NUM_PAGES=${NUM_PAGES:-2000} node md.generate.js" + "postinstall": "del-cli markdown-pages && gatsby clean && NUM_PAGES=${NUM_PAGES:-2000} node md.generate.js" } } diff --git a/scripts/build-benchmark.sh b/scripts/build-benchmark.sh new file mode 100755 index 0000000000000..1a5c94a8db47c --- /dev/null +++ b/scripts/build-benchmark.sh @@ -0,0 +1,33 @@ +#!/bin/bash -eux + +set -e +set -u +set -x + +BENCHMARKS=( + # create-pages + # image-processing + markdown_id + markdown_slug + markdown_table + # plugin-manifest + # query +) + +SIZES=( + 1000 + 5000 + 10000 + 25000 + # 100000 +) + +cd benchmarks +for benchmark in "${BENCHMARKS[@]}"; do + cd "${benchmark}" + for num in "${SIZES[@]}"; do + NUM_PAGES=${num} npm install + NUM_PAGES=${num} ./node_modules/.bin/gatsby build + done + cd .. +done