-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from AikidoSec/dev
Add GitHub action to verify that difference is less than 8%
- Loading branch information
Showing
5 changed files
with
91 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Benchmark | ||
on: push | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
services: | ||
mongodb: | ||
image: mongo:5 | ||
env: | ||
"MONGO_INITDB_ROOT_USERNAME": "root" | ||
"MONGO_INITDB_ROOT_PASSWORD": "password" | ||
ports: | ||
- 27017:27017 | ||
timeout-minutes: 5 | ||
strategy: | ||
matrix: | ||
node-version: [18.x] | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- run: make install | ||
- run: make build | ||
- name: Run Benchmark | ||
id: benchmark | ||
run: cd benchmarks/mongodb && node benchmark.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
const { exec } = require("child_process"); | ||
|
||
async function runScript(scriptPath) { | ||
return new Promise((resolve, reject) => { | ||
exec(`node ${scriptPath}`, (error, stdout, stderr) => { | ||
if (error) { | ||
reject(error); | ||
} | ||
if (stderr) { | ||
reject(stderr); | ||
} | ||
resolve(stdout); | ||
}); | ||
}); | ||
} | ||
|
||
async function main(times = 10, maxDiffInPercentage = 10) { | ||
const results = []; | ||
for (let i = 0; i < times; i++) { | ||
const withGuard = await runScript("withGuard.js"); | ||
const { averageTimeInMS: withGuardTimeInMS } = JSON.parse(withGuard); | ||
const withoutGuard = await runScript("withoutGuard.js"); | ||
const { averageTimeInMS: withoutGuardTimeInMS } = JSON.parse(withoutGuard); | ||
results.push({ | ||
withGuardTimeInMS, | ||
withoutGuardTimeInMS, | ||
differenceInPercentage: Math.abs( | ||
((withGuardTimeInMS - withoutGuardTimeInMS) / withoutGuardTimeInMS) * | ||
100 | ||
), | ||
}); | ||
} | ||
|
||
const averageDifferenceInPercentage = | ||
results | ||
.map((r) => r.differenceInPercentage) | ||
.reduce((acc, diff) => acc + diff, 0) / results.length; | ||
|
||
if (averageDifferenceInPercentage > maxDiffInPercentage) { | ||
console.error( | ||
`The difference between the two benchmarks is too high: ${averageDifferenceInPercentage.toFixed( | ||
3 | ||
)}%` | ||
); | ||
console.error(results); | ||
process.exit(1); | ||
} else { | ||
console.log( | ||
`The difference between the two benchmarks is acceptable: ${averageDifferenceInPercentage.toFixed( | ||
3 | ||
)}%` | ||
); | ||
} | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters