int versus float (sum) (v4)

Revision 4 of this benchmark created by electricessence on


Description

Let's compare apples to apples.

We will use the for loop itself as the arithmetic mechanism.

Need to be sure types are kept consistent.

Setup

var
      int_0 = 0 | 0,
      max = 10000,
      maxInt = max | 0,
      maxFloat = 1
      incrementInt = 1 | 0,
      incrementFloat = 1/max;
    
    var resultInt = int_0, resultFloat = 0;

Teardown


    resultInt = int_0;
    resultFloat = 0;
  

Test runner

Ready to run.

Testing in
TestOps/sec
int add
for(var i=int_0; i<maxInt; i+=incrementInt) {
  resultInt += i;
}
ready
float add (fraction)
for(var i=0; i<maxFloat; i+=incrementFloat) {
  resultFloat += i;
}
ready
float add (fraction constant)
for(var i=0; i<max; i+=1) {
  resultFloat += incrementFloat;
}
ready
int add (no | 0)
for(var i=0; i<max; i+=1) {
  resultInt += i;
}
ready
float add (integer)
for(var i=0; i<max; i+=1) {
  resultFloat += i;
}
ready

Revisions

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