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 21, 2022
1 parent a9745e3 commit fa3f043
Show file tree
Hide file tree
Showing 13 changed files with 660 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
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
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
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
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
24 changes: 24 additions & 0 deletions test/benchmark/README.md
@@ -0,0 +1,24 @@
# 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 benchmark an older version 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>

Powered by [Benchmark.js](https://benchmarkjs.com/).
41 changes: 41 additions & 0 deletions test/benchmark/bench.js
@@ -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 });

0 comments on commit fa3f043

Please sign in to comment.