Simple speed benchmark results

Everything else that doesn't fall into one of the other PB categories.
OgreVorbis
User
User
Posts: 77
Joined: Thu Jan 16, 2020 10:47 pm

Re: Simple speed benchmark results

Post by OgreVorbis »

User_Russian wrote: Tue Dec 21, 2021 3:52 pm
OgreVorbis wrote: Mon Dec 20, 2021 8:26 pmPB 5.73 (x64) - 1.59 - 98MB - 15KB
Need result PB 6.00 C Backend with optimize generated code.
Yes, I agree. That will be my next test.
Do you know if there is any conflicts installing the C version (as long as I make a new program files folder)?
My blog/software site: http://dosaidsoft.com/
User avatar
IceSoft
Addict
Addict
Posts: 1616
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Re: Simple speed benchmark results

Post by IceSoft »

I think allocating memory should not part of the measurement.
Better:

Code: Select all

Dim Nums(lim)
Define StartTime.d = ElapsedMilliseconds()

; Use a basic Sieve of Eratosthenes
...
Belive!
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
OgreVorbis
User
User
Posts: 77
Joined: Thu Jan 16, 2020 10:47 pm

Re: Simple speed benchmark results

Post by OgreVorbis »

IceSoft wrote: Tue Dec 21, 2021 5:28 pm I think allocating memory should not part of the measurement.
Better:

Code: Select all

Dim Nums(lim)
Define StartTime.d = ElapsedMilliseconds()

; Use a basic Sieve of Eratosthenes
...
No. It should be because all the other ones were written this way. Plus, I'm benchmarking the whole process, including memory allocation. However, I doubt it varies much between languages anyway.

blueb wrote: Tue Dec 21, 2021 2:59 pm OgreVorbis... I find this all very interesting.

Results from my desktop computer...
It took 0.578 seconds to complete.
Using assembly version...
It took 0.401 seconds to complete.

As you can see from my profile, I have a faster machine. So hardware is important.

I believe that choosing a language that is easy to use outweighs speed, as long as the result is 'fast enough' to do the job.

My take on this... if you selected a programming language that requires less staff you will save more by lowering your payroll costs than by trying to squeeze every bit of performance by changing languages.
Yes, I agree. I still love PB even though it's not as fast as some others. I'm very surprised though because it seems much faster to me than my C# programs, but that's not based on statistical facts.
And yes, my PC is an AMD FX-8350. I still use it for my development because I want to see my performance on a more average system when I write software. If I were to write it on my super fast Ryzen 7, it wouldn't be as aligned with real world scenarios. Plus, I got this system customized over the years, running Win 7.

Coming up soon will be the C backend and VB6, but I have something more important I have to finish right now.

Oh and again, will there be conflicts with the C backend version installed alongside the normal 5.73?
My blog/software site: http://dosaidsoft.com/
Jeff8888
User
User
Posts: 38
Joined: Fri Jan 31, 2020 6:48 pm

Re: Simple speed benchmark results

Post by Jeff8888 »

Since there seems to be further interest in this topic, I have posted an improved version of the my previous post. Main improvement is to skip testing even numbers in main loop and to use Repeat...Until instead of For...Next loop. Since the tests discussed in "Dave's Garage" youtube channel are for calculating primes up to one million, I changed program to do this as the default number if you enter zero. Did this 100 times to get meaningful times. On my I3-3240 pc get about 0.38 secs for regular code and 0.134 secs for assembly code. Main advantage of assembly is using R registers for variables.

Regular Code

Code: Select all

Dim Nums.a(0)
Define.l i,l, n, m, limit,limitroot,two_n

If OpenConsole()
  
  ; Ask for the limit to search, get that input and allocate a Array
  Print("Enter limit for this search: ")
  limit = Val(Input())
  If limit=0
    limit=1000000 ;default if zero input
  EndIf
  
  Define StartTime.d = ElapsedMilliseconds()
  For i=1 To 100
   ReDim Nums(limit)  ;Initially set all numbers as prime (=0)
    limitroot=Sqr(limit)
    
    ; Use a basic Sieve of Eratosthenes
    ; Mark even numbers, except 2 as not prime
    n=4
    Repeat
      nums(n)+1
      n=n+2
    Until n>limit
    ;Sieve rest of the numbers
    n=3
    Repeat
      If Nums(n) = 0   ;Find next prime
        m = n * n      ;All smaller multiples of n already marked so skip
        two_n=n+n
        ;This loop is where the program spends most of its time
        Repeat
          Nums(m)+1      ;mark multiples of m as not prime
          m = m + two_n  ;can skip even multiples of m as already marked
        Until m>limit
      EndIf
      n= n+2  ;skip next number which is even
    Until n>limitroot
  Next
  Define EndTime.d = (ElapsedMilliseconds() - StartTime) / 1000.0
  PrintN("It took " + StrD(EndTime) + " seconds to complete.")
  Print("Press ENTER to list results. . . ") : Input()
  PrintN(#CRLF$ + "The primes up to " + Str(limit) + " are:")
  m = 0
  For n = 2 To limit
    If Nums(n) = #False
      ;PrintN(Str(n))
      m = m + 1
    EndIf
  Next
  PrintN(#CRLF$ + "The number of primes up to " + Str(limit) + " is: "+Str(m))
  Dim pcount(20)
  For i=0 To 9
    If i=0
      pcount(i)=pcount(i)-2
    EndIf
    For j=i*limit/10 To i*limit/10+limit/10-1
      If Nums(j) = #False
        ;PrintN(Str(n))
        pcount(i)=pcount(i)+1
      EndIf
      
    Next
    PrintN("Num Primes from "+Str(i*limit/10)+" To " +Str(i*limit/10+limit/10-1)+" is "+Str(pcount(i)))
  Next
  Print(#CRLF$ + "Press ENTER to exit"): Input()
  CloseConsole()
EndIf
Assembly Code

Code: Select all

Dim Nums.b(0)

Define.l i,m,n 
If OpenConsole()
  
  ; Ask for the limit to search, get that input and allocate a Array
  Print("Enter limit for this search: ")
  limit = Val(Input())
  If limit=0
    limit=1000000 ;default if zero input
  EndIf
  
  Define StartTime.d = ElapsedMilliseconds()
  For i=1 To 100
    ReDim Nums(limit)
    limitroot=Sqr(limit)
    ; Use a basic Sieve of Eratosthenes
    
    ;Initialize registers
    ! MOV rbp,qword [a_Nums]
    ! MOV r8,qword [v_limitroot]
    ! MOV r9, qword [v_limit]
    
    ;n=4
    ! MOV    r11,4
    
    ;Repeat
    ! _Repeat7:
    ; nums(n)+1
    !MOV   byte [rbp+r11],1
    
    ; n=n+2
    !ADD r11,2
    
    ; Until n>limit
    !CMP    r11,r9
    !JLE   _Repeat7
    
    ;n=3
    ! MOV    r11,3
    
    ; Repeat
    !_Repeat8:
    ; If Nums(n) = 0
    !MOVSX  r15,byte [rbp+r11]
    !AND    r15,r15
    !JNE   _EndIfxx
    
    ; m = n * n
    !MOV r10,R11
    !IMUL r10,R11
    
    ; two_n=n+n
    !MOV r13,r11
    !ADD r13,r11
    
    ;Note the next loop is where the program spends most of its time
    ;Repeat
    !_Repeat11:
    ; Nums(m)+1
    !MOV    byte [rbp+r10],1
    ;m = m + two_n
    !ADD r10,r13
    
    ;Until m>limit
    !CMP    r10,r9
    !JLE   _Repeat11
    
    ; EndIf
    !_EndIfxx:
    
    ; n= n+2
    !add r11,2
    ; Until n>limitroot
    ! CMP    r11,r8
    ! JLE   _Repeat8
    !_Until8:
    
  Next
  Define EndTime.d = (ElapsedMilliseconds() - StartTime) / 1000.0
  PrintN("It took " + StrD(EndTime) + " seconds to complete.")
  Print("Press ENTER to list results. . . ") : Input()
  PrintN(#CRLF$ + "The primes up to " + Str(limit) + " are:")
  m = 0
  For n = 2 To limit
    If Nums(n) = #False
      ;PrintN(Str(n))
      m = m + 1
    EndIf
  Next
  PrintN(#CRLF$ + "The number of primes up to " + Str(limit) + " is: "+Str(m))
  Dim pcount.l(20)
  For i=0 To 9
    If i=0
      pcount(i)=pcount(i)-2
    EndIf
    For j=i*limit/10 To i*limit/10+limit/10-1
      If Nums(j) = #False
        ;PrintN(Str(n))
        pcount(i)=pcount(i)+1
      EndIf
      
    Next
    PrintN("Num Primes from "+Str(i*limit/10)+" To " +Str(i*limit/10+limit/10-1)+" is "+Str(pcount(i)))
  Next
  Print(#CRLF$ + "Press ENTER to exit"): Input()
  CloseConsole()
EndIf
pfaber11
Enthusiast
Enthusiast
Posts: 145
Joined: Sat Apr 13, 2019 12:17 pm

Re: Simple speed benchmark results

Post by pfaber11 »

These tests are useful to know .Was surprised by freebasics results . Looked at freebasic a few months ago and it isn't for me although for free it could be a good option for some people . Thanks for sharing your results. I wonder where PB 6 would come in the list . What was the point of the new c backend , will it increase the speed ?
User avatar
Tenaja
Addict
Addict
Posts: 1949
Joined: Tue Nov 09, 2010 10:15 pm

Re: Simple speed benchmark results

Post by Tenaja »

pfaber11 wrote: Sat Jun 04, 2022 12:17 pm What was the point of the new c backend , will it increase the speed ?
The point was to port pb to the new arm based mac. It makes new architectural targets trivial compared to creating new architectural asm output. Case in point: raspberry pi was released at the same time.

Yes, in many cases it will be faster, simply because the c compiler has many decades of optimizations with many contributors.

However, if you activate those optimization options, compile time will be significantly longer.
pfaber11
Enthusiast
Enthusiast
Posts: 145
Joined: Sat Apr 13, 2019 12:17 pm

Re: Simple speed benchmark results

Post by pfaber11 »

There we are thanks for putting me straight I now see the point .
Post Reply