Welcome! Log In Create A New Profile

Advanced

for/to loop count up vs down and int vs long - odd perf result

December 24, 2011 12:58AM
Re performance.

Comparing performance I see unexpected results - any comments on the following.

Counting up with Int
for ( i:Int <- 0 to 500000000) { }
took 859ms

Counting up with Long is massively slower ..
for ( i: Long <- 0L to 500000000L) {}
took 5000ms

Counting down is much faster and about same timing with int or long

for ( i:Int <- 500000000 to 0 ) {}
took 341ms

for ( i:Long <- 500000000L to 0L ) {}
took 343ms


CPU : Core i5 M520
Scala 2.9.1


Tried while loop too ..

Count up or down with int took 2 ms
Count up/down with long took 632/431ms

The while test were variants of ..

var i:Long = 500000000L
while ( i > 0L ) {
i -= 1
}



Edited 2 time(s). Last edit at 12/24/2011 01:05AM by johnlon.
Subject Author Views Posted

for/to loop count up vs down and int vs long - odd perf result

johnlon 2997 December 24, 2011 12:58AM

Re: for/to loop count up vs down and int vs long - odd perf result

Antoras 471 December 24, 2011 12:02PM

Re: for/to loop count up vs down and int vs long - odd perf result

johnlon 649 December 26, 2011 05:09AM

Re: for/to loop count - relative and absolute performance

user unknown 419 January 09, 2012 07:37AM

Re: for/to loop count - relative and absolute performance

johnlon 572 January 22, 2012 04:09AM