PureBasic speed test compared to this video

Everything else that doesn't fall into one of the other PB categories.
cas
Enthusiast
Enthusiast
Posts: 597
Joined: Mon Nov 03, 2008 9:56 pm

Re: PureBasic speed test compared to this video

Post by cas »

NicTheQuick wrote:With macros and the avoidance of modulo you actually can make it pretty fast. And that is what a C compiler usually does automatically for you:

Code: Select all

 
It is surprising to me that threadsafe option makes it faster. Here are my results with this code:
PB 5.73 x64 without debugger:
threadsafe disabled:
Passes: 1585, Time: 5001 ms, Avg: 3.155 ms, Limit: 1000000, Count: 78498, Valid: 1
threadsafe enabled:
Passes: 2176, Time: 5001 ms, Avg: 2.298 ms, Limit: 1000000, Count: 78498, Valid: 1

Also tested it with MSVC release mode /O2 on the same PC:
x86:
Passes: 4898, Time: 5.000000, Avg: 0.001021, Limit: 1000000, Count: 78498, Valid: 1
x64:
Passes: 5049, Time: 5.000000, Avg: 0.000990, Limit: 1000000, Count: 78498, Valid: 1
User avatar
NicTheQuick
Enthusiast
Enthusiast
Posts: 786
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: PureBasic speed test compared to this video

Post by NicTheQuick »

On my system I see no differences between with and without the threadsafe option enabled. Is this maybe a Windows only thing?
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
cas
Enthusiast
Enthusiast
Posts: 597
Joined: Mon Nov 03, 2008 9:56 pm

Re: PureBasic speed test compared to this video

Post by cas »

Yes, Windows 10 x64.
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1074
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: PureBasic speed test compared to this video

Post by Paul »

I don't see "Thread Safe" being faster (Windows 10 x64 / PB 5.73 x64 without debugger)...

Normal:
Passes: 3074, Time: 5000 ms, Avg: 1.627 ms, Limit: 1000000, Count: 78498, Valid: 1

Thread Safe:
Passes: 3064, Time: 5000 ms, Avg: 1.632 ms, Limit: 1000000, Count: 78498, Valid: 1
Image Image
cas
Enthusiast
Enthusiast
Posts: 597
Joined: Mon Nov 03, 2008 9:56 pm

Re: PureBasic speed test compared to this video

Post by cas »

I tested it many times and i always get around 30% speed difference. Also i tested it on old celeron laptop also with windows 10 x64 and threadsafe version is also faster but only by 10%. Both systems are with intel cpu. Do you maybe have amd?
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1074
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: PureBasic speed test compared to this video

Post by Paul »

cas wrote:Do you maybe have amd?
Intel i7-10700K here. Very strange why you see such a difference when using Thread Safe on your systems.
Image Image
cas
Enthusiast
Enthusiast
Posts: 597
Joined: Mon Nov 03, 2008 9:56 pm

Re: PureBasic speed test compared to this video

Post by cas »

I finally figured out why i get that huge difference. I made a mistake and was compiling with PB 5.72 and not PB 5.73. It looks like there was a problem in PB 5.72 compiler (and maybe in older versions). Here are new results (average from 5 runs):

5.72 x64:
threadsafe enabled: 2072
threadsafe disabled: 1557

5.73 x64:
threadsafe enabled: 2137
threadsafe disabled: 2133

6.00 alpha 1 x64 pb
threadsafe enabled: 2150
threadsafe disabled: 2173

6.00 alpha 1 x64 c
optimization disabled: 2264
optimization enabled: 4614

C backend is a huge improvement. Even without optimizations i get a small performance boost.
Olli
Enthusiast
Enthusiast
Posts: 400
Joined: Wed May 27, 2020 12:26 pm

Re: PureBasic speed test compared to this video

Post by Olli »

Maybe adapt the right asm instructions to compare :

Code: Select all

Define max.I = 1048576
Dim ps.I(max - 1)

Define *ps = @ps(0)
ps(0) = %11 ; one (bit 1) and zero (bit 0) are not prime
t0 = ElapsedMilliseconds()

! mov rdx, [v_max]
! mov r9, [p_ps]
! shl rdx, 6
! xor rax, rax ; the test starts from zero plus one
thenextone:
! inc rax ; we test everything, the even ones, even...
! bt qword [r9], rax ; if GetBit(rax)
! jc l_thenextone ; goto thenextone: endif
isprime:
! mov r8, rax
! imul r8, r8
! cmp r8, rdx
! jae l_fin
stamp:
! bts qword [r9], r8 ; BitSet(r8)
! lea r8, [r8+rax]
! cmp r8, rdx
! jb l_stamp
! jmp l_thenextone
fin:
t1 = ElapsedMilliseconds()
Debug max * 64
For i = max - 16 To max - 1
Debug Str(i) + " : " + Bin(ps(i) )
Next
Debug Str(t1 - t0) + " ms"
Thank you Google search
Post Reply