diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml new file mode 100644 index 0000000..1f06eec --- /dev/null +++ b/.github/workflows/benchmark.yml @@ -0,0 +1,30 @@ +name: Benchmark PR + +on: + pull_request_target: + types: + - labeled + +jobs: + benchmark: + if: ${{ github.event.label.name == 'benchmark' }} + uses: fastify/workflows/.github/workflows/plugins-benchmark-pr.yml@main + with: + npm-script: benchmark + + remove-label: + if: "always()" + needs: + - benchmark + runs-on: ubuntu-latest + steps: + - name: Remove benchmark label + uses: octokit/request-action@v2.x + id: remove-label + with: + route: DELETE /repos/{repo}/issues/{issue_number}/labels/{name} + repo: ${{ github.event.pull_request.head.repo.full_name }} + issue_number: ${{ github.event.pull_request.number }} + name: benchmark + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/test/benchmark.js b/benchmark/benchmark.js similarity index 83% rename from test/benchmark.js rename to benchmark/benchmark.js index 6e52182..bfc3871 100644 --- a/test/benchmark.js +++ b/benchmark/benchmark.js @@ -1,3 +1,5 @@ +'use strict' + const http = require('http') const Benchmark = require('benchmark') @@ -52,17 +54,18 @@ const mockReqCookiesPayload = { } } -suite.add('Request', function () { - new Request(mockReq) -}) +suite + .add('Request', function () { + new Request(mockReq) // eslint-disable-line no-new + }) .add('Custom Request', function () { - new Request.CustomRequest(mockCustomReq) + new Request.CustomRequest(mockCustomReq) // eslint-disable-line no-new }) .add('Request With Cookies', function () { - new Request(mockReqCookies) + new Request(mockReqCookies) // eslint-disable-line no-new }) .add('Request With Cookies n payload', function () { - new Request(mockReqCookiesPayload) + new Request(mockReqCookiesPayload) // eslint-disable-line no-new }) .add('ParseUrl', function () { parseURL('http://example.com:8080/hello') @@ -77,7 +80,4 @@ suite.add('Request', function () { .on('cycle', function (event) { console.log(String(event.target)) }) - .on('complete', function () { - console.log('Fastest is: ' + this.filter('fastest').map('name')) - }) .run() diff --git a/package.json b/package.json index b65bc03..1c6b20b 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "tsd": "^0.28.0" }, "scripts": { - "benchmark": "node test/benchmark.js", + "benchmark": "node benchmark/benchmark.js", "coverage": "npm run unit -- --cov --coverage-report=html", "lint": "standard", "test": "npm run lint && npm run test:unit && npm run test:typescript",