mirror of
https://github.com/liabru/matter-js.git
synced 2025-01-20 17:10:11 -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-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": [
|
||||
|
|
|
@ -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 (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];
|
||||
for (i = 0; i < options.repeats; i += 1) {
|
||||
if (global.gc) {
|
||||
global.gc();
|
||||
}
|
||||
|
||||
const pairsList = engine.pairs.list;
|
||||
const pairsListLength = engine.pairs.list.length;
|
||||
const Examples = requireUncached('../examples/index');
|
||||
const example = Examples[options.name]();
|
||||
|
||||
for (let p = 0; p < pairsListLength; p += 1) {
|
||||
const pair = pairsList[p];
|
||||
const separation = pair.separation - pair.slop;
|
||||
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;
|
||||
|
||||
if (pair.isActive && !pair.isSensor) {
|
||||
overlapTotal += separation > 0 ? separation : 0;
|
||||
overlapCount += 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;
|
||||
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -10,7 +10,8 @@ const {
|
|||
comparisonReport,
|
||||
logReport,
|
||||
toMatchExtrinsics,
|
||||
toMatchIntrinsics
|
||||
toMatchIntrinsics,
|
||||
getArg
|
||||
} = require('./TestTools');
|
||||
|
||||
const Example = requireUncached('../examples/index');
|
||||
|
@ -18,9 +19,11 @@ 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'];
|
||||
|
@ -42,6 +45,7 @@ const captureExamples = async useDev => {
|
|||
name,
|
||||
useDev,
|
||||
updates: 2,
|
||||
repeats: 1,
|
||||
stableSort: true,
|
||||
jitter: excludeJitter.includes(name) ? 0 : 1e-10
|
||||
})));
|
||||
|
@ -50,6 +54,7 @@ const captureExamples = async useDev => {
|
|||
name,
|
||||
useDev,
|
||||
updates: 2,
|
||||
repeats: 1,
|
||||
stableSort: true,
|
||||
jitter: excludeJitter.includes(name) ? 0 : 1e-10
|
||||
})));
|
||||
|
@ -58,6 +63,7 @@ const captureExamples = async useDev => {
|
|||
name,
|
||||
useDev,
|
||||
updates: 2,
|
||||
repeats: 1,
|
||||
stableSort: false,
|
||||
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({
|
||||
name,
|
||||
useDev,
|
||||
updates: 150,
|
||||
updates: updates,
|
||||
repeats: repeats,
|
||||
stableSort: false,
|
||||
jitter: excludeJitter.includes(name) ? 0 : 1e-10
|
||||
})));
|
||||
|
|
|
@ -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');
|
||||
|
@ -286,6 +291,6 @@ const toMatchIntrinsics = {
|
|||
};
|
||||
|
||||
module.exports = {
|
||||
requireUncached, comparisonReport, logReport,
|
||||
requireUncached, comparisonReport, logReport, getArg,
|
||||
serialize, toMatchExtrinsics, toMatchIntrinsics
|
||||
};
|
Loading…
Add table
Reference in a new issue