mirror of
https://github.com/liabru/matter-js.git
synced 2025-01-21 17:14:38 -05:00
added repeats and updates options to test tools
This commit is contained in:
parent
0f0ac93921
commit
6142991e0a
4 changed files with 60 additions and 41 deletions
|
@ -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-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-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-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",
|
"test-watch": "npm run test-node -- --watch",
|
||||||
"changelog": "conventional-changelog -i CHANGELOG.md -s -r",
|
"changelog": "conventional-changelog -i CHANGELOG.md -s -r",
|
||||||
"release": "npm version --no-git-tag-version",
|
"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"
|
"version": "git checkout -b release/$npm_package_version && npm run build"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
|
|
|
@ -13,50 +13,57 @@ const runExample = options => {
|
||||||
frameCallbacks
|
frameCallbacks
|
||||||
} = prepareEnvironment(options);
|
} = 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 totalMemory = 0;
|
||||||
let totalDuration = 0;
|
let totalDuration = 0;
|
||||||
let overlapTotal = 0;
|
let overlapTotal = 0;
|
||||||
let overlapCount = 0;
|
let overlapCount = 0;
|
||||||
let i;
|
let i;
|
||||||
|
let j;
|
||||||
if (global.gc) {
|
|
||||||
global.gc();
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (i = 0; i < options.updates; i += 1) {
|
let runner;
|
||||||
const time = i * runner.delta;
|
let engine;
|
||||||
const callbackCount = frameCallbacks.length;
|
let render;
|
||||||
|
|
||||||
for (let p = 0; p < callbackCount; p += 1) {
|
for (i = 0; i < options.repeats; i += 1) {
|
||||||
totalMemory += process.memoryUsage().heapUsed;
|
if (global.gc) {
|
||||||
const callback = frameCallbacks.shift();
|
global.gc();
|
||||||
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 Examples = requireUncached('../examples/index');
|
||||||
const pairsListLength = engine.pairs.list.length;
|
const example = Examples[options.name]();
|
||||||
|
|
||||||
for (let p = 0; p < pairsListLength; p += 1) {
|
runner = example.runner;
|
||||||
const pair = pairsList[p];
|
engine = example.engine;
|
||||||
const separation = pair.separation - pair.slop;
|
render = example.render;
|
||||||
|
|
||||||
|
for (j = 0; j < options.updates; j += 1) {
|
||||||
|
const time = j * runner.delta;
|
||||||
|
const callbackCount = frameCallbacks.length;
|
||||||
|
|
||||||
if (pair.isActive && !pair.isSensor) {
|
for (let p = 0; p < callbackCount; p += 1) {
|
||||||
overlapTotal += separation > 0 ? separation : 0;
|
totalMemory += process.memoryUsage().heapUsed;
|
||||||
overlapCount += 1;
|
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;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,7 +82,7 @@ const runExample = options => {
|
||||||
};
|
};
|
||||||
|
|
||||||
} catch (err) {
|
} 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;
|
throw err;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,7 +10,8 @@ const {
|
||||||
comparisonReport,
|
comparisonReport,
|
||||||
logReport,
|
logReport,
|
||||||
toMatchExtrinsics,
|
toMatchExtrinsics,
|
||||||
toMatchIntrinsics
|
toMatchIntrinsics,
|
||||||
|
getArg
|
||||||
} = require('./TestTools');
|
} = require('./TestTools');
|
||||||
|
|
||||||
const Example = requireUncached('../examples/index');
|
const Example = requireUncached('../examples/index');
|
||||||
|
@ -18,9 +19,11 @@ const MatterBuild = requireUncached('../build/matter');
|
||||||
const { versionSatisfies } = requireUncached('../src/core/Plugin');
|
const { versionSatisfies } = requireUncached('../src/core/Plugin');
|
||||||
const Worker = require('jest-worker').default;
|
const Worker = require('jest-worker').default;
|
||||||
|
|
||||||
const specificExamples = process.env.EXAMPLES ? process.env.EXAMPLES.split(' ') : null;
|
const testComparison = getArg('compare', null) === 'true';
|
||||||
const testComparison = process.env.COMPARE === 'true';
|
const saveComparison = getArg('save', null) === 'true';
|
||||||
const saveComparison = process.env.SAVE === '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 excludeExamples = ['svg', 'terrain'];
|
||||||
const excludeJitter = ['stack', 'circleStack', 'restitution', 'staticFriction', 'friction', 'newtonsCradle', 'catapult'];
|
const excludeJitter = ['stack', 'circleStack', 'restitution', 'staticFriction', 'friction', 'newtonsCradle', 'catapult'];
|
||||||
|
@ -42,6 +45,7 @@ const captureExamples = async useDev => {
|
||||||
name,
|
name,
|
||||||
useDev,
|
useDev,
|
||||||
updates: 2,
|
updates: 2,
|
||||||
|
repeats: 1,
|
||||||
stableSort: true,
|
stableSort: true,
|
||||||
jitter: excludeJitter.includes(name) ? 0 : 1e-10
|
jitter: excludeJitter.includes(name) ? 0 : 1e-10
|
||||||
})));
|
})));
|
||||||
|
@ -50,6 +54,7 @@ const captureExamples = async useDev => {
|
||||||
name,
|
name,
|
||||||
useDev,
|
useDev,
|
||||||
updates: 2,
|
updates: 2,
|
||||||
|
repeats: 1,
|
||||||
stableSort: true,
|
stableSort: true,
|
||||||
jitter: excludeJitter.includes(name) ? 0 : 1e-10
|
jitter: excludeJitter.includes(name) ? 0 : 1e-10
|
||||||
})));
|
})));
|
||||||
|
@ -58,6 +63,7 @@ const captureExamples = async useDev => {
|
||||||
name,
|
name,
|
||||||
useDev,
|
useDev,
|
||||||
updates: 2,
|
updates: 2,
|
||||||
|
repeats: 1,
|
||||||
stableSort: false,
|
stableSort: false,
|
||||||
jitter: excludeJitter.includes(name) ? 0 : 1e-10
|
jitter: excludeJitter.includes(name) ? 0 : 1e-10
|
||||||
})));
|
})));
|
||||||
|
@ -72,7 +78,8 @@ const captureExamples = async useDev => {
|
||||||
const completeRuns = await Promise.all(examples.map(name => singleThreadWorker.runExample({
|
const completeRuns = await Promise.all(examples.map(name => singleThreadWorker.runExample({
|
||||||
name,
|
name,
|
||||||
useDev,
|
useDev,
|
||||||
updates: 150,
|
updates: updates,
|
||||||
|
repeats: repeats,
|
||||||
stableSort: false,
|
stableSort: false,
|
||||||
jitter: excludeJitter.includes(name) ? 0 : 1e-10
|
jitter: excludeJitter.includes(name) ? 0 : 1e-10
|
||||||
})));
|
})));
|
||||||
|
|
|
@ -254,6 +254,11 @@ const requireUncached = path => {
|
||||||
return module;
|
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 = {
|
const toMatchExtrinsics = {
|
||||||
toMatchExtrinsics(received, value) {
|
toMatchExtrinsics(received, value) {
|
||||||
const similaritys = extrinsicSimilarity(received, value, 'extrinsic');
|
const similaritys = extrinsicSimilarity(received, value, 'extrinsic');
|
||||||
|
@ -286,6 +291,6 @@ const toMatchIntrinsics = {
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
requireUncached, comparisonReport, logReport,
|
requireUncached, comparisonReport, logReport, getArg,
|
||||||
serialize, toMatchExtrinsics, toMatchIntrinsics
|
serialize, toMatchExtrinsics, toMatchIntrinsics
|
||||||
};
|
};
|
Loading…
Add table
Reference in a new issue