Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
wasm-watermarker
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nagayama15
wasm-watermarker
Commits
43e4b627
Verified
Commit
43e4b627
authored
Jan 05, 2020
by
nagayama15
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🆕
Add ammo.js benchmark
parent
4f0298e8
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
196 additions
and
0 deletions
+196
-0
benchmark.js
example/ammo.js/benchmark.js
+39
-0
stress.js
example/ammo.js/stress.js
+157
-0
No files found.
example/ammo.js/benchmark.js
0 → 100644
View file @
43e4b627
require
(
"./testutils"
);
const
stress
=
require
(
"./stress"
);
(
async
()
=>
{
const
runBench
=
dir
=>
{
const
Ammo
=
require
(
`./
${
dir
}
/ammo.wasm`
);
return
new
Promise
(
resolve
=>
{
console
.
log
(
`Run bench:
${
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
wasms
=
[
"ammo.js/builds"
,
"ammo-1-0c9c85c7"
,
"ammo-1-0d97880d"
,
"ammo-1-60b725f1"
,
"ammo-1-fe8191b3"
,
"ammo-2-0c9c85c7"
,
"ammo-2-0d97880d"
,
"ammo-2-60b725f1"
,
"ammo-2-fe8191b3"
,
"ammo-3-0c9c85c7"
,
"ammo-3-0d97880d"
,
"ammo-3-60b725f1"
,
"ammo-3-fe8191b3"
];
for
(
wasm
of
wasms
)
{
await
runBench
(
wasm
);
}
})();
example/ammo.js/stress.js
0 → 100644
View file @
43e4b627
// 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
);
var
overlappingPairCache
=
new
Ammo
.
btDbvtBroadphase
();
var
solver
=
new
Ammo
.
btSequentialImpulseConstraintSolver
();
var
dynamicsWorld
=
new
Ammo
.
btDiscreteDynamicsWorld
(
dispatcher
,
overlappingPairCache
,
solver
,
collisionConfiguration
);
dynamicsWorld
.
setGravity
(
new
Ammo
.
btVector3
(
0
,
-
10
,
0
));
var
groundShape
=
new
Ammo
.
btBoxShape
(
new
Ammo
.
btVector3
(
50
,
50
,
50
));
var
bodies
=
[];
var
groundTransform
=
new
Ammo
.
btTransform
();
groundTransform
.
setIdentity
();
groundTransform
.
setOrigin
(
new
Ammo
.
btVector3
(
0
,
-
56
,
0
));
(
function
()
{
var
mass
=
0
;
var
localInertia
=
new
Ammo
.
btVector3
(
0
,
0
,
0
);
var
myMotionState
=
new
Ammo
.
btDefaultMotionState
(
groundTransform
);
var
rbInfo
=
new
Ammo
.
btRigidBodyConstructionInfo
(
0
,
myMotionState
,
groundShape
,
localInertia
);
var
body
=
new
Ammo
.
btRigidBody
(
rbInfo
);
dynamicsWorld
.
addRigidBody
(
body
);
bodies
.
push
(
body
);
})();
var
sphereShape
=
new
Ammo
.
btSphereShape
(
1
);
var
boxShape
=
new
Ammo
.
btBoxShape
(
new
Ammo
.
btVector3
(
1
,
1
,
1
));
var
coneShape
=
new
Ammo
.
btConeShape
(
1
,
1
);
// XXX TODO: add cylindershape too
[
sphereShape
,
boxShape
,
coneShape
,
boxShape
,
sphereShape
,
coneShape
].
forEach
(
function
(
shape
,
i
)
{
var
startTransform
=
new
Ammo
.
btTransform
();
startTransform
.
setIdentity
();
var
mass
=
1
;
var
localInertia
=
new
Ammo
.
btVector3
(
0
,
0
,
0
);
shape
.
calculateLocalInertia
(
mass
,
localInertia
);
startTransform
.
setOrigin
(
new
Ammo
.
btVector3
(
2
+
i
*
0.01
,
10
+
i
*
2.1
,
0
)
);
var
myMotionState
=
new
Ammo
.
btDefaultMotionState
(
startTransform
);
var
rbInfo
=
new
Ammo
.
btRigidBodyConstructionInfo
(
mass
,
myMotionState
,
shape
,
localInertia
);
var
body
=
new
Ammo
.
btRigidBody
(
rbInfo
);
dynamicsWorld
.
addRigidBody
(
body
);
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()!"
);
}
benchmark
();
if
(
TEST_MEMORY
)
testDestroy
();
}
module
.
exports
=
stress
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment