Skip to content

Commit

Permalink
ci: benchmark workflow (#253)
Browse files Browse the repository at this point in the history
* ci: benchmark workflow

* Apply suggestions from code review
  • Loading branch information
Uzlopak authored Aug 31, 2023
1 parent 952ec36 commit 1e335fa
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
@@ -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 }}
18 changes: 9 additions & 9 deletions test/benchmark.js → benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

const http = require('http')

const Benchmark = require('benchmark')
Expand Down Expand Up @@ -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')
Expand All @@ -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()
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 1e335fa

Please sign in to comment.