Page 1 of 3

PureBench32 progress laughable, consistancy question!

Posted: Thu Oct 09, 2008 4:35 pm
by pdwyer
So, after this thread http://www.purebasic.fr/english/viewtop ... sc&start=0 I thought I'd try hacking something together so that I could get an idea if this was going to be difficult or not. I want to start with the obvious CPU benchmark and work up to memory, disk IO etc later.

Having written almost no code I hit a consistancy issue that has me confused. I've seen a few people post similar sorts of questions so I figure that one of those ASM decompiler people might be able to tell me what happening.

Below are two programs, they are almost identical. The first one does some simple math with longs, then floats, the second one does the same thing with longs then the second part with doubles.

Not supprisingly, longs are faster than floats which are faster than doubles but why are longs faster when paired with doubles than they are with floats? Shouldn't they be about the same? It's always a 10% difference

Output is:

(FLOATS)
Starting...
Integer Iterations: 543523
Floating Point Iterations: 419996

(DOUBLES)
Starting...
Integer Iterations: 629507
Floating Point Iterations: 92694

:shock:

Is it just me? There are only three character changes in the code samples .f changed to .d in three places and nothing in the scope of the longs where the difference is being seen

Code is (Doubles):

Code: Select all

Global TimeToRun.l = 5000
Global IntIterations.l
Global FpIterations.l

OpenConsole()

    Timer.d = ElapsedMilliseconds()
    IntIterations = 0
    
    PrintN("Starting...")
    Delay(20)
    
    While ElapsedMilliseconds() < Timer + TimeToRun
        IntA.l = 1234
        IntB.l = 4321
        IntIterations = IntIterations + 1
        For i = 1 To 1000
            iAns.l = IntA + IntB
            iAns = IntA - IntB
            iAns = IntB % IntA
            iAns = IntA * IntB
            IntA = IntA + i
            IntB = IntB - i
        Next      
    Wend

    PrintN("Integer Iterations: " + Str(IntIterations))
    
    Timer.d = ElapsedMilliseconds()
    FpIterations = 0
    Delay(100)  ;let the cpus calm down
    
    While ElapsedMilliseconds() < Timer + TimeToRun
        FPA.d = 1234.1234
        FPB.d = 4321.4321
        FpIterations = FpIterations + 1
        For i = 1 To 1000
            fAns.d = FPA + FPB
            fAns = FPA - FPB
            fAns = FPB / FPA
            fAns = FPA * FPB
            FPA = FPA + i
            FPB = FPB - i
        Next      
    Wend
    
    PrintN("Floating Point Iterations: " + Str(FPIterations))
    Input()

CloseConsole()
and then floats

Code: Select all



Global TimeToRun.l = 5000
Global IntIterations.l
Global FpIterations.l

OpenConsole()

    Timer.d = ElapsedMilliseconds()
    IntIterations = 0
    
    PrintN("Starting...")
    Delay(20)
    
    While ElapsedMilliseconds() < Timer + TimeToRun
        IntA.l = 1234
        IntB.l = 4321
        IntIterations = IntIterations + 1
        For i = 1 To 1000
            iAns.l = IntA + IntB
            iAns = IntA - IntB
            iAns = IntB % IntA
            iAns = IntA * IntB
            IntA = IntA + i
            IntB = IntB - i
        Next      
    Wend

    PrintN("Integer Iterations: " + Str(IntIterations))
    
    Timer.d = ElapsedMilliseconds()
    FpIterations = 0
    Delay(100)  ;let the cpus calm down
    
    While ElapsedMilliseconds() < Timer + TimeToRun
        FPA.f = 1234.1234
        FPB.f = 4321.4321
        FpIterations = FpIterations + 1
        For i = 1 To 1000
            fAns.f = FPA + FPB
            fAns = FPA - FPB
            fAns = FPB / FPA
            fAns = FPA * FPB
            FPA = FPA + i
            FPB = FPB - i
        Next      
    Wend
    
    PrintN("Floating Point Iterations: " + Str(FPIterations))
    Input()

CloseConsole()


Posted: Thu Oct 09, 2008 4:46 pm
by ts-soft
floats wrote:Integer Iterations: 286486
Floating Point Iterations: 581142
double wrote:Integer Iterations: 284824
Floating Point Iterations: 268197

Posted: Thu Oct 09, 2008 4:48 pm
by Trond
Probably an alignment issue.

Posted: Thu Oct 09, 2008 5:01 pm
by pdwyer
TS-Soft, what is your CPU? I'm curious if this is reflecting speed differences still, I won't have a chance to test this on other systems for another week. EDIT: Hang on, your floats are faster than your ints! :? this is even less realistic than I thought :o

Thanks Trond, I didn't consider that (because I don't know all that much about it). Is there a way to control that or is it system dependant?

Posted: Thu Oct 09, 2008 5:17 pm
by ts-soft
> TS-Soft, what is your CPU?
AMD X2 6000+ (Sockel AM2)

Posted: Thu Oct 09, 2008 5:55 pm
by Demivec
My results are:
floats wrote:Integer Iterations: 202212
Floating Point Iterations: 416628
double wrote:Integer Iterations: 203759
Floating Point Iterations: 190614
Running on an AMD Athlon 64 Processor 3500+ 1.79 GHz.

Posted: Thu Oct 09, 2008 7:00 pm
by Rook Zimbabwe
Probably an alignment issue.
Naaah... Paul is Neutral Good if he is anything! {{Bad Dungeons & Dragons joke here!}}

OK my silly thought...

All numbers are really binary to the computer. Could it be the conversion of those numbers to binary that is the lag? or at least have something to do with the lag?

Posted: Thu Oct 09, 2008 10:49 pm
by Road Runner
Code alignment/misalignment can easily change timings for small loops by as much 20%.
You can demonstrate alignment differences by inserting ASM NOP statements immediately ahead of your loop. Time the loop, insert one more NOP, time the loop, insert one more NOP .. until you have 16 or 32 NOPs and then the timing variations should start to repeat.

Best solution, if alignment is the cause, is to carefully align your code.
Doesn't FASM have an ALIGN directive which you can use with inline ASM to fix the alignment on a 32 byte boundary so your subsequent BASIC code blocks always run with known alignment?

Posted: Fri Oct 10, 2008 6:22 am
by pdwyer
:shock: Role player alert! :shock:
Been there done that. :wink:

Is code alignment based on the addresses of the variables being used or the code that executes it (or am I speaking out of my ass)? If I call the from a fuction can I match the alignment better I wonder...

Anyway, I'll keep going. I'm still not sure why some poeple have faster floats that ints with this code, it implies the benchmark is flawed.

Posted: Fri Oct 10, 2008 8:23 am
by djes
Insert this kind of code before the critical part to resolve alignment issues :

Code: Select all

Goto f
!SECTION '.testf' CODE READABLE EXECUTABLE ALIGN 4096
f:
My personal alignment is loyal bad ;)

Posted: Fri Oct 10, 2008 9:09 am
by blueznl
I'm an Amber Diceless player, where do I fit in? :shock: Or sign up 8)

Total off-topic thread hi-jacking. Okay. I'll go back to my corner and sulk a little more... :P

Posted: Fri Oct 10, 2008 9:27 am
by pdwyer
:lol: blast from the past! Amber :roll:

A friend of mine tried to get some other friends and I into that about 15 years ago... Role playing without dice is like coffee without caffeine!

I haven't done any role playing since moving to Japan 10 years ago now. probably the only reason I managed to keep my marriage ;)

Posted: Fri Oct 10, 2008 9:35 am
by pdwyer
djes wrote:Insert this kind of code before the critical part to resolve alignment issues :

Code: Select all

Goto f
!SECTION '.testf' CODE READABLE EXECUTABLE ALIGN 4096
f:
My personal alignment is loyal bad ;)
I'm not seeing much of a difference, if I put it just before the first while loop or not it still is effected as to whether the second part is double or float.

let me play with this some more... (but I suspect I've got it in the wrong place as I don't know what I'm doing with that

thanks

Posted: Fri Oct 10, 2008 10:16 am
by djes
Your code should be like that. Depending on the situation, I've different results, but always better with aligned code. Sometimes, the first part could be aligned too.

Code: Select all


Global TimeToRun.l = 5000
Global IntIterations.l
Global FpIterations.l

OpenConsole()


    IntIterations = 0
   
    PrintN("Starting...")
    Delay(20)

    Timer.d = ElapsedMilliseconds() 

    While ElapsedMilliseconds() < Timer + TimeToRun
        IntA.l = 1234
        IntB.l = 4321
        IntIterations = IntIterations + 1
        For i = 1 To 1000
            iAns.l = IntA + IntB
            iAns = IntA - IntB
            iAns = IntB % IntA
            iAns = IntA * IntB
            IntA = IntA + i
            IntB = IntB - i
        Next     
    Wend

    PrintN("Integer Iterations: " + Str(IntIterations))
   
    FpIterations = 0
    Delay(100)  ;let the cpus calm down

    Timer.d = ElapsedMilliseconds()
   
    While ElapsedMilliseconds() < Timer + TimeToRun
        FPA.d = 1234.1234
        FPB.d = 4321.4321
        FpIterations = FpIterations + 1
        For i = 1 To 1000
            fAns.d = FPA + FPB
            fAns = FPA - FPB
            fAns = FPB / FPA
            fAns = FPA * FPB
            FPA = FPA + i
            FPB = FPB - i
        Next     
    Wend
   
    PrintN("Floating Point Iterations: " + Str(FPIterations))

    IntIterations = 0
   
    PrintN("Starting...")
    Delay(20)

  
Goto f
!SECTION '.testf' CODE READABLE EXECUTABLE ALIGN 4096
f:

    Timer.d = ElapsedMilliseconds()

    While ElapsedMilliseconds() < Timer + TimeToRun
        IntA.l = 1234
        IntB.l = 4321
        IntIterations = IntIterations + 1
        For i = 1 To 1000
            iAns.l = IntA + IntB
            iAns = IntA - IntB
            iAns = IntB % IntA
            iAns = IntA * IntB
            IntA = IntA + i
            IntB = IntB - i
        Next     
    Wend

    PrintN("Integer Iterations: " + Str(IntIterations))  

    FpIterations = 0
    Delay(100)  ;let the cpus calm down
  
Goto g
!SECTION '.testf' CODE READABLE EXECUTABLE ALIGN 4096
g:

    Timer.d = ElapsedMilliseconds()

    While ElapsedMilliseconds() < Timer + TimeToRun
        FPA.d = 1234.1234
        FPB.d = 4321.4321
        FpIterations = FpIterations + 1
        For i = 1 To 1000
            fAns.d = FPA + FPB
            fAns = FPA - FPB
            fAns = FPB / FPA
            fAns = FPA * FPB
            FPA = FPA + i
            FPB = FPB - i
        Next     
    Wend
   
    PrintN("Floating Point Iterations: " + Str(FPIterations))
    Input()

CloseConsole() 

Posted: Fri Oct 10, 2008 10:44 am
by pdwyer
Doesn't really help does it

Changing around the float or double code still effects int code and effects it the same way in the aligned section or not.

:?