typechecking

Benchmark created on


Preparation HTML

<script>
  var i = -1,
      n = 1000,
      rand = [],
      a = [],
      b = [],
      c = [],
      d = [];
  while (++i < n) {
   rand.push(~~ (Math.random() * 1000));
  }
  console.log(rand);
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
fill whole arrays
var t = rand[0];
i = -1;
a = []
while (++i < n) {
 a.push((rand[i] > t) ? [t, 0, 0] : [t, 0, 1]);
}
ready
fill mixed arrays
var t = rand[0];
i = -1
b = []
while (++i < n) {
 b.push((rand[i] > t) ? [t, 0, 0] : t);
}
ready
fill whole objects
var t = rand[0];
i = -1;
c = []
while (++i < n) {
 c.push((rand[i] > t) ? {
  start: t,
  stop: 0,
  step: 0
 } : {
  start: t,
  stop: 0,
  step: 1
 });
}
ready
fill mixed objects
var t = rand[0];
i = -1
d = []
while (++i < n) {
 d.push((rand[i] > t) ? {
  start: t,
  stop: 0,
  step: 0
 } : t);
}
ready
test val from whole arrays
var s;
i = -1;
while (++i < n) {
 if (a[i][2]) s = a[i][0];
}
ready
test type from mixed arrays
var s;
i = -1;
while (++i < n) {
 if (typeof b[i] == "number") s = b[i];
}
ready
test val from whole objects
var s;
i = -1;
while (++i < n) {
 if (c[i].step) s = c[i].start;
}
ready
test type from whole objects
var s;
i = -1;
while (++i < n) {
 if (typeof d[i] == "number") s = d[i];
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.