Verified Commit 22e43969 authored by nagayama15's avatar nagayama15

Update benchmark

parent 11f605fa
require("./testutils");
const stress = require("./stress");
const WARM = 3;
const N = 10 + WARM;
(async () => {
const runBench = dir => {
const Ammo = require(`./${dir}/ammo.wasm`);
return new Promise(resolve => {
console.log(`Run bench: ${dir}`);
console.error(`${dir}`);
// Wrap `Ammo()` by real `Promise` object because it returns just Promise-like object
// and awaiting it acts buggy.
Ammo().then(Ammo => {
stress(Ammo);
resolve();
const durs = [];
for (let i = 0; i < N; i++) {
const dur = stress(Ammo);
durs.push(dur);
console.error(dur);
}
resolve({ dir, durs });
});
});
};
......@@ -33,7 +41,10 @@ const stress = require("./stress");
"dist/ammo-3-fe8191b3"
];
const results = [];
for (wasm of wasms) {
await runBench(wasm);
results.push(await runBench(wasm));
}
console.log(JSON.stringify(results));
})();
// From ammo.js/tests/stress.js
function stress(Ammo) {
// Stress test
var TEST_MEMORY = 0;
var readMemoryCeiling, malloc;
if (TEST_MEMORY) {
(function() {
try {
STATICTOP;
readMemoryCeiling = function() {
return STATICTOP + _sbrk.DATASIZE;
};
malloc = _malloc;
} catch (e) {
var mapping = getClosureMapping();
var key = "0";
readMemoryCeiling = eval(
"(function() { return " +
mapping["STATICTOP"] +
" + " +
mapping["_sbrk$DATASIZE"] +
" })"
);
malloc = eval(mapping["_malloc"]);
}
})();
}
function benchmark() {
var collisionConfiguration = new Ammo.btDefaultCollisionConfiguration();
var dispatcher = new Ammo.btCollisionDispatcher(collisionConfiguration);
......@@ -100,58 +73,19 @@ function stress(Ammo) {
bodies.push(body);
});
var memoryStart;
var startTime = Date.now();
if (TEST_MEMORY) malloc(5 * 1024 * 1024); // stress memory usage
var NUM = 150000;
for (var i = 0; i < NUM; i++) {
if (i === 250 && TEST_MEMORY) memoryStart = readMemoryCeiling();
dynamicsWorld.stepSimulation(1 / 60, 10);
}
var endTime = Date.now();
if (TEST_MEMORY)
assertEq(
readMemoryCeiling(),
memoryStart,
"Memory ceiling must remain stable!"
);
print("total time: " + ((endTime - startTime) / 1000).toFixed(3));
}
function testDestroy() {
var NUM = 1000; // enough to force an increase in the memory ceiling
var vec = new Ammo.btVector3(4, 5, 6);
var memoryStart = readMemoryCeiling();
for (var i = 0; i < NUM; i++) {
Ammo.destroy(vec);
vec = new Ammo.btVector3(4, 5, 6);
}
Ammo.destroy(vec);
assertEq(
readMemoryCeiling(),
memoryStart,
"Memory ceiling must remain stable!"
);
for (var i = 0; i < NUM; i++) {
vec = new Ammo.btVector3(4, 5, 6);
}
assertNeq(
readMemoryCeiling(),
memoryStart,
"Memory ceiling must increase without destroy()!"
);
return (endTime - startTime) / 1000;
}
benchmark();
if (TEST_MEMORY) testDestroy();
return benchmark();
}
module.exports = stress;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment