Page 1 of 2
Processing performance of floats vs integers?
Posted: Tue Oct 07, 2008 12:23 am
by Mistrel
Why is it that running this same piece of code with floats produces almost no CPU activity while using integers uses about 25%?
Code: Select all
Repeat
n.f+1
If n.f=100000
Delay(1)
n.f=0
EndIf
ForEver
Code: Select all
Repeat
n+1
If n=100000
Delay(1)
n=0
EndIf
ForEver
Posted: Tue Oct 07, 2008 4:02 am
by venom
Would the FPU come up as CPU usage?
Posted: Tue Oct 07, 2008 9:36 am
by djes
Flawed test I think! How many times is it repeated in 1 second? I doubt it's the same!
Posted: Tue Oct 07, 2008 11:23 am
by Trond
Integers are usually a bit faster, but it depends on how the expression is translated into assembly. There is a rather heavy penalty for mixing integers and floats in the same expression, though, since it adds the extra operation of converting to the correct format.
Your test is flawed. Delay(1) waits at least 1 millisecond. But it could wait 5000 if the computer is under heavy load from higher priority processes.
You need to time it all in one go (so the timer inaccuracy gets less significant) and with the debugger off.
With this test I get:
Float: 1722
Integer: 618
Quad: 3896
Double: 3805
But this test may be a bit unfair because the expressions are so short. Floats always have to be loaded onto the FPU, manipulated and stored back to memory. But integer operations can be done directly on memory, and in this case, when i is incremented, PB does not use a CPU register for it. So it's faster. More complex integer expressions will be done in the CPU registers, so there will be an extra penalty for transferring the numbers in and out of there.
Code: Select all
#Tries = 2000
time = GetTickCount_()
For U = 0 To #Tries
Repeat
n.f + 1
If n = 100000
n = 0
Break
EndIf
ForEver
Next
MessageRequester("float", Str(GetTickCount_()-time))
time = GetTickCount_()
For U = 0 To #Tries
Repeat
i.l + 1
If i = 100000
i = 0
Break
EndIf
ForEver
Next
MessageRequester("integer", Str(GetTickCount_()-time))
time = GetTickCount_()
For U = 0 To #Tries
Repeat
q.q + 1
If q = 100000
q = 0
Break
EndIf
ForEver
Next
MessageRequester("quad", Str(GetTickCount_()-time))
Posted: Tue Oct 07, 2008 11:39 am
by charvista
The double gives also high performances.
Code: Select all
time = GetTickCount_()
For U = 0 To #Tries
Repeat
d.d + 1
If d = 100000
d = 0
Break
EndIf
ForEver
Next
MessageRequester("double", Str(GetTickCount_()-time))
My results were:
Float: 2844
Integer: 968
Quad: 2781
Double: 1328
Posted: Tue Oct 07, 2008 11:50 am
by Trond
charvista wrote:My results were:
Float: 2844
Integer: 968
Quad: 2781
Double: 1328
Strange. What cpu do you have? My floats and integers are faster, but quads and doubles are much slower.
Float: 1722
Integer: 618
Quad: 3896
Double: 3805
Posted: Tue Oct 07, 2008 12:05 pm
by Mistrel
E4300:
Float: 1344
Integer: 906
Quad: 2344
Double: 1312
T9300:
Float: 906
Integer: 563
Quad: 1437
Double: 813
Posted: Tue Oct 07, 2008 1:20 pm
by djes
Processor performance can't be evaluated on such tests. On modern processors, floating point operations are blazing fast! Personally If I have floats in my code, I don't do conversion as I did by the past to make things faster with integers. However, some things, like conditional tests (if, for, etc.) are faster in integer.
Posted: Tue Oct 07, 2008 1:29 pm
by charvista
I'm using AMD Athlon 64 Processor 3200+ @2.01Ghz with 2.00GB RAM.
Having Vista Ultimate, the Windows Experience Index shows:
Processor: 4.1
Memory: 4.9
Graphics: 3.2
Gaming Graphics: 3.0
Primary hard disk: 5.8
The compiled program run again shows now:
Float: 2969
Integer: 1047
Quad: 5343
Double: 1328
Of course, the speed depends of the activities of the cpu in the background. It is clear however that the Integer and the Double do have the best performances. Quad is the slowest of all.
Posted: Tue Oct 07, 2008 3:55 pm
by Trond
djes wrote:Processor performance can't be evaluated on such tests. On modern processors, floating point operations are blazing fast!
I'm just amazed that my 5 year old processor still beats the new 64-bit monsters running at 1.5 times higher clock frequency on the integer test.
Posted: Tue Oct 07, 2008 4:09 pm
by djes
There's a lot of things to consider. The first being using 32 bits long on a 64 bits system is just bad, caches and buses are not designed for that.
Posted: Tue Oct 07, 2008 7:45 pm
by Demivec
I'm using AMD Athlon 64 Processor 3500+ @994Mhz with 2.00GB RAM using Windows XP SP3.
My results are:
Float: 1297
Integer: 609
Quad: 2531
Double: 1328
As with Trond, my older system outdid a new system such as charvista's. I did match him on the Double speed though.
Posted: Tue Oct 07, 2008 7:57 pm
by MrMat
Tronds code is reeeeeally slow to link here (about 20 seconds) with the debugger off. With the debugger on it compiles and links almost instantly. It is the same on two different machines i've tried (XP and Vista 64). Does anyone else get that?
Posted: Wed Oct 08, 2008 2:30 am
by pdwyer
Anyone interested in putting heads together and writing a little benchmark tool? Obviously it needs to be a little more sophisiticated but I'm often looking for small non-installed benchmark tools that check cpu, memory, disk IO etc.
It strikes me that the these forums would get good feedback on what kinds of tests are meaningful and which are pointless.
Just a thought. I do mean
little though, I'm not suggesting large projects and souce code management, I'm thinking < 1000 lines of code for a finished tool with people passing along a function or a comment about it.
Ok, knock me down in flames now

Posted: Wed Oct 08, 2008 3:33 am
by Mistrel
I think you have a very cool idea, pdwyer. I wish I could help but it's already been demonstrated that I know nothing about writing benchmark routines. Best of luck to you and anyone else who wants to participate.
