Skip to content

Commit

Permalink
Test: Add benchmark for QUnit.equiv()
Browse files Browse the repository at this point in the history
Ref #1327.
  • Loading branch information
Krinkle committed Sep 29, 2022
1 parent a9745e3 commit 56689ae
Show file tree
Hide file tree
Showing 13 changed files with 662 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
}
},
{
"files": ["test/es2018/**"],
"files": ["test/benchmark/**", "test/es2018/**"],
"env": {
"es2017": true
},
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ jobs:
# ```
# root@ubuntu-tmp/qunit$ apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y libmozjs-68-dev
# root@ubuntu-tmp/qunit$ js68 test/mozjs.js
# root@ubuntu-tmp/qunit$ js68 test/benchmark/index-mozjs.js
# ```
sm-test:
name: SpiderMonkey
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
/docs/.jekyll-cache/
/docs/_site/
/docs/Gemfile.lock
/test/benchmark/package-lock.json
/test/benchmark/node_modules/
/test/integration/*/package-lock.json
/test/integration/*/node_modules/
/node_modules/
Expand Down
33 changes: 33 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"@rollup/plugin-commonjs": "^20.0.0",
"@rollup/plugin-node-resolve": "^13.0.4",
"@rollup/plugin-replace": "^3.0.0",
"benchmark": "2.1.4",
"eslint": "7.32.0",
"eslint-config-semistandard": "^16.0.0",
"eslint-config-standard": "^16.0.3",
Expand Down
26 changes: 26 additions & 0 deletions test/benchmark/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Benchmark for QUnit internals

## Usage

The default is to benchmark the local development version of QUnit.

1. Install QUnit for development and generate the release artefact:
* `qunit$ npm ci`
* `qunit$ npm run build`
2. Link benchmark to local artefact.
NOTE: Alternatively, you can edit benchmark/package.json
and change `file:../..` to something like `2.19.1` to
benchmark older versions of QUnit.
* `qunit/test/benchmark$ npm install`
3. Run the benchmark
* In Node.js:
`qunit/test/benchmark$ node index-node.js`
* In a browser:
* Start a static web server, e.g. using Python
`qunit$ python3 -m http.server 4000`
or PHP:
`php -S localhost:4000`
* Open <http://localhost:4000/test/benchmark/index-browser.html>
* Check the console output.

Powered by [Benchmark.js](https://benchmarkjs.com/).
41 changes: 41 additions & 0 deletions test/benchmark/bench.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* global require, globalThis, QUnitFixtureEquiv, QUnit, console */

const Benchmark = typeof require === 'function' ? require('benchmark') : globalThis.Benchmark;
const suite = new Benchmark.Suite();

// Check for correctness first, mainly for the return value,
// but also for any unexpected exceptions as Benchmark will tolerate
// uncaught exceptions as being benchmarkable behaviour.
for (const group of QUnitFixtureEquiv) {
group.pairs.forEach((pair, i) => {
const res = QUnit.equiv(pair.a, pair.b);
if (res !== pair.equal) {
throw new Error(`Unexpected return value in "${group.name}" at pairs[${i}]\n Expected: ${pair.equal}\n Actual: ${res}`);
}
});
}

suite.add('equiv', function () {
for (const group of QUnitFixtureEquiv) {
for (const pair of group.pairs) {
QUnit.equiv(pair.a, pair.b);
}
}
});

for (const group of QUnitFixtureEquiv) {
suite.add(`equiv (${group.name})`, function () {
for (const pair of group.pairs) {
QUnit.equiv(pair.a, pair.b);
}
});
}

console.log('Running benchmark...');
suite.on('cycle', function (event) {
console.log(String(event.target));
});
suite.on('complete', function () {
console.log('Done!');
});
suite.run({ async: true });
Loading

0 comments on commit 56689ae

Please sign in to comment.