-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add test case for copy function
- Loading branch information
Showing
2 changed files
with
39 additions
and
4 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,32 @@ | ||
const { describe, it, before } = require('node:test'); | ||
const assert = require('node:assert'); | ||
const copyBench = require('./fixtures/copy'); | ||
|
||
describe('Same benchmark function', () => { | ||
let results; | ||
|
||
before(async () => { | ||
results = await copyBench.run(); | ||
}); | ||
|
||
it('must have a similar benchmark result', () => { | ||
for (let i = 0; i < results.length; i++) { | ||
for (let j = 0; j < results.length; j++) { | ||
if (i !== j) { | ||
const opsSec1 = results[i].opsSec; | ||
const opsSec2 = results[j].opsSec; | ||
|
||
// Calculate the percentage difference | ||
const difference = Math.abs(opsSec1 - opsSec2); | ||
const percentageDifference = (difference / Math.min(opsSec1, opsSec2)) * 100; | ||
|
||
// Check if the percentage difference is less than or equal to 10% | ||
assert.ok( | ||
percentageDifference <= 10, | ||
`${opsSec1} too different from ${opsSec2} - ${results[i].name}` | ||
); | ||
} | ||
} | ||
} | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,16 +1,19 @@ | ||
const { Suite } = require('../../lib'); | ||
|
||
const suite = new Suite(); | ||
const suite = new Suite({ reporter: false }); | ||
|
||
suite | ||
.add('Using includes', function () { | ||
const text = 'text/html,application/xhtml+xml,application/xml;application/json;q=0.9,image/avif,image/webp,*/*;q=0.8' | ||
const r = text.includes('application/json') | ||
return r; | ||
}) | ||
.add('Using includes 2', function () { | ||
const text = 'text/html,application/xhtml+xml,application/xml;application/json;q=0.9,image/avif,image/webp,*/*;q=0.8' | ||
const r = text.includes('application/json') | ||
return r; | ||
}) | ||
.run({ reporter: true }); | ||
.add('Using includes 3', function () { | ||
const text = 'text/html,application/xhtml+xml,application/xml;application/json;q=0.9,image/avif,image/webp,*/*;q=0.8' | ||
const r = text.includes('application/json') | ||
}) | ||
|
||
module.exports = suite; |