Skip to content

Commit

Permalink
added repeats and updates options to test tools
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed Aug 13, 2023
1 parent 0f0ac93 commit 6142991
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 40 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@
"test-node": "npm run build-dev && node --expose-gc node_modules/.bin/jest --force-exit --no-cache --runInBand ./test/Examples.spec.js",
"test-browser": "node --expose-gc node_modules/.bin/jest --force-exit --no-cache --runInBand ./test/Browser.spec.js",
"test-all": "npm run test-node && npm run test-browser",
"test-save": "SAVE=true npm run test-node",
"test-save": "npm run test-node -- --save=true",
"test-watch": "npm run test-node -- --watch",
"changelog": "conventional-changelog -i CHANGELOG.md -s -r",
"release": "npm version --no-git-tag-version",
"preversion": "git checkout master && npm run lint && SAVE=true npm run test-all",
"preversion": "git checkout master && npm run lint && npm run test-all -- --save=true",
"version": "git checkout -b release/$npm_package_version && npm run build"
},
"files": [
Expand Down
71 changes: 39 additions & 32 deletions test/ExampleWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,50 +13,57 @@ const runExample = options => {
frameCallbacks
} = prepareEnvironment(options);

const Examples = requireUncached('../examples/index');
const example = Examples[options.name]();

const engine = example.engine;
const runner = example.runner;
const render = example.render;

let totalMemory = 0;
let totalDuration = 0;
let overlapTotal = 0;
let overlapCount = 0;
let i;

if (global.gc) {
global.gc();
}
let j;

try {
for (i = 0; i < options.updates; i += 1) {
const time = i * runner.delta;
const callbackCount = frameCallbacks.length;
let runner;
let engine;
let render;

for (i = 0; i < options.repeats; i += 1) {
if (global.gc) {
global.gc();
}

for (let p = 0; p < callbackCount; p += 1) {
totalMemory += process.memoryUsage().heapUsed;
const callback = frameCallbacks.shift();
const startTime = process.hrtime();
const Examples = requireUncached('../examples/index');
const example = Examples[options.name]();

callback(time);
runner = example.runner;
engine = example.engine;
render = example.render;

for (j = 0; j < options.updates; j += 1) {
const time = j * runner.delta;
const callbackCount = frameCallbacks.length;

const duration = process.hrtime(startTime);
totalMemory += process.memoryUsage().heapUsed;
totalDuration += duration[0] * 1e9 + duration[1];
}
for (let p = 0; p < callbackCount; p += 1) {
totalMemory += process.memoryUsage().heapUsed;
const callback = frameCallbacks.shift();
const startTime = process.hrtime();

callback(time);

const duration = process.hrtime(startTime);
totalMemory += process.memoryUsage().heapUsed;
totalDuration += duration[0] * 1e9 + duration[1];
}

const pairsList = engine.pairs.list;
const pairsListLength = engine.pairs.list.length;
const pairsList = engine.pairs.list;
const pairsListLength = engine.pairs.list.length;

for (let p = 0; p < pairsListLength; p += 1) {
const pair = pairsList[p];
const separation = pair.separation - pair.slop;
for (let p = 0; p < pairsListLength; p += 1) {
const pair = pairsList[p];
const separation = pair.separation - pair.slop;

if (pair.isActive && !pair.isSensor) {
overlapTotal += separation > 0 ? separation : 0;
overlapCount += 1;
if (pair.isActive && !pair.isSensor) {
overlapTotal += separation > 0 ? separation : 0;
overlapCount += 1;
}
}
}
}
Expand All @@ -75,7 +82,7 @@ const runExample = options => {
};

} catch (err) {
err.message = `On example '${options.name}' update ${i}:\n\n ${err.message}`;
err.message = `On example '${options.name}' update ${j}:\n\n ${err.message}`;
throw err;
}
};
Expand Down
17 changes: 12 additions & 5 deletions test/Examples.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@ const {
comparisonReport,
logReport,
toMatchExtrinsics,
toMatchIntrinsics
toMatchIntrinsics,
getArg
} = require('./TestTools');

const Example = requireUncached('../examples/index');
const MatterBuild = requireUncached('../build/matter');
const { versionSatisfies } = requireUncached('../src/core/Plugin');
const Worker = require('jest-worker').default;

const specificExamples = process.env.EXAMPLES ? process.env.EXAMPLES.split(' ') : null;
const testComparison = process.env.COMPARE === 'true';
const saveComparison = process.env.SAVE === 'true';
const testComparison = getArg('compare', null) === 'true';
const saveComparison = getArg('save', null) === 'true';
const specificExamples = getArg('examples', null, (val) => val.split(','));
const repeats = getArg('repeats', 1, parseFloat);
const updates = getArg('updates', 150, parseFloat);

const excludeExamples = ['svg', 'terrain'];
const excludeJitter = ['stack', 'circleStack', 'restitution', 'staticFriction', 'friction', 'newtonsCradle', 'catapult'];
Expand All @@ -42,6 +45,7 @@ const captureExamples = async useDev => {
name,
useDev,
updates: 2,
repeats: 1,
stableSort: true,
jitter: excludeJitter.includes(name) ? 0 : 1e-10
})));
Expand All @@ -50,6 +54,7 @@ const captureExamples = async useDev => {
name,
useDev,
updates: 2,
repeats: 1,
stableSort: true,
jitter: excludeJitter.includes(name) ? 0 : 1e-10
})));
Expand All @@ -58,6 +63,7 @@ const captureExamples = async useDev => {
name,
useDev,
updates: 2,
repeats: 1,
stableSort: false,
jitter: excludeJitter.includes(name) ? 0 : 1e-10
})));
Expand All @@ -72,7 +78,8 @@ const captureExamples = async useDev => {
const completeRuns = await Promise.all(examples.map(name => singleThreadWorker.runExample({
name,
useDev,
updates: 150,
updates: updates,
repeats: repeats,
stableSort: false,
jitter: excludeJitter.includes(name) ? 0 : 1e-10
})));
Expand Down
7 changes: 6 additions & 1 deletion test/TestTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,11 @@ const requireUncached = path => {
return module;
};

const getArg = (name, defaultValue=null, parser=(v) => v) => {
const value = process.argv.find(arg => arg.startsWith(`--${name}=`));
return value ? parser(value.split('=')[1]) : defaultValue;
};

const toMatchExtrinsics = {
toMatchExtrinsics(received, value) {
const similaritys = extrinsicSimilarity(received, value, 'extrinsic');
Expand Down Expand Up @@ -286,6 +291,6 @@ const toMatchIntrinsics = {
};

module.exports = {
requireUncached, comparisonReport, logReport,
requireUncached, comparisonReport, logReport, getArg,
serialize, toMatchExtrinsics, toMatchIntrinsics
};

0 comments on commit 6142991

Please sign in to comment.