Page 2 of 2

Re: PureBasic speed test compared to this video

Posted: Sun Mar 28, 2021 3:32 am
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

Re: PureBasic speed test compared to this video

Posted: Sun Mar 28, 2021 7:16 pm
by NicTheQuick
On my system I see no differences between with and without the threadsafe option enabled. Is this maybe a Windows only thing?

Re: PureBasic speed test compared to this video

Posted: Mon Mar 29, 2021 12:22 am
by cas
Yes, Windows 10 x64.

Re: PureBasic speed test compared to this video

Posted: Mon Mar 29, 2021 4:52 am
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

Re: PureBasic speed test compared to this video

Posted: Tue Mar 30, 2021 11:14 am
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?

Re: PureBasic speed test compared to this video

Posted: Tue Mar 30, 2021 3:36 pm
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.

Re: PureBasic speed test compared to this video

Posted: Wed May 19, 2021 8:54 pm
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.

Re: PureBasic speed test compared to this video

Posted: Sun Jun 13, 2021 10:24 pm
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"