jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
For a dead simple javascript snakes game, where the snake segments are maintained in a simple queue, collision detection must iterate linearly through the queue to check each segment for collision.
This is a simple O(n) algorithm... how large can 'n' be if we need to make this check at least once in every frame (60 fps) for a 64x64 grid
<script>
var size = 64*64, list = null;
for(var n = 0 ; n < size ; n++)
list = { x: size-n, y: size-n, next: list }
function check(x, y, head) {
var segment = head;
while (segment = segment.next) {
if ((x == segment.x) && (y == segment.y))
return true;
}
return false
}
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
1. match early |
| ready |
2. match middle |
| ready |
3. match late |
| ready |
4. no match |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.