Maximum value in array tests
JavaScript performance comparison
Preparation code
<script>
Benchmark.prototype.setup = function() {
a = []
for (i = 0; i < 5000; i++) {
a[i] = Math.round(Math.random() * 100000);
}
function array_max_1(a) {
var max = null;
for (i = a.length - 1; i > -1; i--) {
if (a[i] > max || typeof max === 'null') {
max = a[i];
}
}
return max;
}
function array_max_2(a) {
var max = null;
for (i = a.length - 1; i >= 0; i--) {
if (a[i] > max || typeof max === 'null') {
max = a[i];
}
}
return max;
}
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
array_max_1() |
|
pending… |
array_max_2() |
|
pending… |
Compare results of other browsers
Revisions
You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:
- Revision 1: published
- Revision 2: published
0 comments