PureBench32 progress laughable, consistancy question!

Everything else that doesn't fall into one of the other PB categories.
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

PureBench32 progress laughable, consistancy question!

Post 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()

Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

floats wrote:Integer Iterations: 286486
Floating Point Iterations: 581142
double wrote:Integer Iterations: 284824
Floating Point Iterations: 268197
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Probably an alignment issue.
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post 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?
Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

> TS-Soft, what is your CPU?
AMD X2 6000+ (Sockel AM2)
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Post 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.
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Post 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?
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
Road Runner
User
User
Posts: 48
Joined: Tue Oct 07, 2003 3:10 pm

Post 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?
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post 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.
Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Post 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 ;)
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post 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
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post 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 ;)
Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post 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
Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Post 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() 
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post 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.

:?
Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
Post Reply