Verified Commit 22e43969 authored by nagayama15's avatar nagayama15

Update benchmark

parent 11f605fa
require("./testutils"); require("./testutils");
const stress = require("./stress"); const stress = require("./stress");
const WARM = 3;
const N = 10 + WARM;
(async () => { (async () => {
const runBench = dir => { const runBench = dir => {
const Ammo = require(`./${dir}/ammo.wasm`); const Ammo = require(`./${dir}/ammo.wasm`);
return new Promise(resolve => { 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 // Wrap `Ammo()` by real `Promise` object because it returns just Promise-like object
// and awaiting it acts buggy. // and awaiting it acts buggy.
Ammo().then(Ammo => { Ammo().then(Ammo => {
stress(Ammo); const durs = [];
resolve(); 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"); ...@@ -33,7 +41,10 @@ const stress = require("./stress");
"dist/ammo-3-fe8191b3" "dist/ammo-3-fe8191b3"
]; ];
const results = [];
for (wasm of wasms) { for (wasm of wasms) {
await runBench(wasm); results.push(await runBench(wasm));
} }
console.log(JSON.stringify(results));
})(); })();
// From ammo.js/tests/stress.js // From ammo.js/tests/stress.js
function stress(Ammo) { function stress(Ammo) {
// Stress test // 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() { function benchmark() {
var collisionConfiguration = new Ammo.btDefaultCollisionConfiguration(); var collisionConfiguration = new Ammo.btDefaultCollisionConfiguration();
var dispatcher = new Ammo.btCollisionDispatcher(collisionConfiguration); var dispatcher = new Ammo.btCollisionDispatcher(collisionConfiguration);
...@@ -100,58 +73,19 @@ function stress(Ammo) { ...@@ -100,58 +73,19 @@ function stress(Ammo) {
bodies.push(body); bodies.push(body);
}); });
var memoryStart;
var startTime = Date.now(); var startTime = Date.now();
if (TEST_MEMORY) malloc(5 * 1024 * 1024); // stress memory usage
var NUM = 150000; var NUM = 150000;
for (var i = 0; i < NUM; i++) { for (var i = 0; i < NUM; i++) {
if (i === 250 && TEST_MEMORY) memoryStart = readMemoryCeiling();
dynamicsWorld.stepSimulation(1 / 60, 10); dynamicsWorld.stepSimulation(1 / 60, 10);
} }
var endTime = Date.now(); var endTime = Date.now();
return (endTime - startTime) / 1000;
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()!"
);
} }
benchmark(); return benchmark();
if (TEST_MEMORY) testDestroy();
} }
module.exports = stress; 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