Page 2 of 3
Re: ...PureBasic 2x slower than Java?
Posted: Mon Nov 14, 2011 6:21 pm
by Fred
Well JAVA will probably outperform PB and most C compiler on such benchmarks because they get more informations on the current underlying hardware: as it's a JIT compilation, it can leverage SSE2/3/4, 64 bit and such stuffs if it's present. PB compiles a code which is compatiable with i486. And to be honnest, a whole team is working to optimize JAVA JIT so it's not really a surprise to see it faster. JAVA has evolved a lot, and if you choose the right JVM (server one please, for max speed), it often peroduce best results than C/C++.
Re: ...PureBasic 2x slower than Java?
Posted: Mon Nov 14, 2011 6:51 pm
by Shield
Well, C# and Java
are compilers and they do a great job about optimizing the binaries.
Although they output bytecode, it's still machine code while the application is running and therefore no penalties,
and even better, "just in time" optimization.
I'd also like to see more compiler features rather than new libraries, though.
Edit: oh, Fred was faster there.

Re: ...PureBasic 2x slower than Java?
Posted: Mon Nov 14, 2011 8:10 pm
by Tenaja
Shield wrote:Well, C# and Java
are compilers and they do a great job about optimizing the binaries.
Although they output bytecode, it's still machine code while the application is running and therefore no penalties,
and even better, "just in time" optimization.
I'd also like to see more compiler features rather than new libraries, though.
Edit: oh, Fred was faster there.

Well, sure, sorta...but not really.
C++
consistently is 3x faster than Java and the .NET crew. (At least in the current benchmarks I was researching last month.)
While I wouldn't anticipate a "cafe basic" to be as fast as C++ (although there is no technical reason it cannot be), I would certainly expect it to be faster than anything that puts out a resemblance of bytecode.
Re: ...PureBasic 2x slower than Java?
Posted: Mon Nov 14, 2011 8:28 pm
by Blood
Why do people here think that PB performance will ever come anywhere near Java's?
Java has been developed for many more years than PureBasic and has had some of the best minds in comp-sci working on the compiler and VM. Java has been optimized for runtime speed over and over again. Yeah, Java's startup speed is crap but during runtime Java flies!
Re: ...PureBasic 2x slower than Java?
Posted: Mon Nov 14, 2011 8:59 pm
by Kiffi
Blood wrote: Yeah, Java's startup speed is crap but during runtime Java flies!
same as .NET-Applications.
Greetings ... Kiffi
Re: ...PureBasic 2x slower than Java?
Posted: Mon Nov 14, 2011 9:04 pm
by Blood
Kiffi wrote:Blood wrote: Yeah, Java's startup speed is crap but during runtime Java flies!
same as .NET-Applications.
Greetings ... Kiffi
Yeah but ngen solves some of the startup issues.
Re: ...PureBasic 2x slower than Java?
Posted: Mon Nov 14, 2011 9:11 pm
by Thorium
There is a crazy optimization technic that uses a brute force approach to find to best optimized code. I think its called peep hole super optimizer. It works like a normal beep hole optimizer that replaces code sequenzes with equal faster ones, but it does not get the better code sequenzes from a hand made data base. It generates all possible code sequenzes and checks if they do the same as the code sequenze it want to replace and it checks if it's faster.
Of course compiling that way takes ages but you et the best possible optimized executable.
Re: ...PureBasic 2x slower than Java?
Posted: Mon Nov 14, 2011 9:31 pm
by Ramihyn_
Better algorithms beat compiler optimization anytime, anyway.
Re: ...PureBasic 2x slower than Java?
Posted: Mon Nov 14, 2011 10:15 pm
by luis
Ramihyn_ wrote:Better algorithms beat compiler optimization anytime, anyway.
The idea is to try to apply the optimizations to the "better algorithms".
It's obvious that if you feed crap to the compiler you will only get optimized crap.
Re: ...PureBasic 2x slower than Java?
Posted: Mon Nov 14, 2011 10:46 pm
by Thorium
Ramihyn_ wrote:Better algorithms beat compiler optimization anytime, anyway.
As luis wrote, that statement does not makes sense.
Optimizations do not find new ways to do things. They alter your code to run faster on a specific hardware, so you dont need to care about hardware internals and how to code in a way the CPU is best used. You can concentrate on finding the best algorithm, the compiler makes it even faster for you.
Re: ...PureBasic 2x slower than Java?
Posted: Tue Nov 15, 2011 8:42 am
by Michael Vogel
Still like Remi Meiers
analyzer tool – tells you where all the good time has gone...
...would be interesting, which (non-idle) functions in all PB projects need great parts of the execution time, so optimizing them would be most effective for us all.
Code: Select all
Line Total time (ms) Total time (%) Time per Call Calls Code
35 14266 53,2850265503 14266,0000000000 1 bubbleSort(bubs())
41 6173 23,0568103790 6173,0000000000 1 Input()
11 3341 12,4789896011 0,0001338647 24958036 Swap arr(i),arr(i+1)
16 2979 11,1268815994 0,0001193604 24958036 swapped = #True
30 4 0,0149404248 0,0003999600 10001 bubs(i) = Random(1000000)
23 4 0,0149404248 4,0000000000 1 OpenConsole()
7 2 0,0074702124 0,0002032934 9838 swapped = #False
19 1 0,0037351062 0,0001016467 9838 max = max - 1
39 1 0,0037351062 0,0476190485 21 PrintN(Str(bubs(i)))
26 1 0,0037351062 1,0000000000 1 PrintN(Bubble Sort Test... + Str(size))
42 1 0,0037351062 1,0000000000 1 CloseConsole()
33 0 0,0000000000 0,0000000000 1 time.l = ElapsedMilliseconds()
28 0 0,0000000000 0,0000000000 1 Dim bubs.i(size)
37 0 0,0000000000 0,0000000000 1 PrintN(Time to Complete: + Str(ElapsedMilliseconds() - time))
4 0 0,0000000000 0,0000000000 1 max.i = ArraySize(arr()) - 1
3 0 0,0000000000 0,0000000000 1 swapped.b = #True
25 0 0,0000000000 0,0000000000 1 size.l = 10000
24 0 0,0000000000 0,0000000000 1 RandomSeed(0)
Re: ...PureBasic 2x slower than Java?
Posted: Tue Nov 15, 2011 9:25 am
by Danilo
I would be happy if PureBasic would not include unneeded procedures. If you use
many includes, the exe is 'bloated' with unnecessary procedures.
Alone with my gDrawing include, a simple test like:
Code: Select all
XIncludeFile "gDrawing.pbi"
If gInit()
gEnd()
EndIf
includes 23 procedures. Only 2 are needed, 21 procedures are included unnecessary.
I had to make a /COMMENTED output, remove the 21 macro use lines (MPxxx) and /REASM.
Does not affect speed, but with many includes and procedures your exe's can become very big
because of included dead code.
Re: ...PureBasic 2x slower than Java?
Posted: Tue Nov 15, 2011 10:21 am
by wilbert
ASM attemp [32 bit] to see if there's a lot of speed difference
Code: Select all
Procedure bubbleSortASM(Array arr.i(1))
Protected size.i = ArraySize(arr())
Protected base.i = @arr()
EnableASM
mov ecx, size
mov edx, base
!push ebx
!push ebp
!push edi
!push esi
!cmp ecx, 2 ; exit if size < 2
!jl bs_exit
!btr ebp, 0 ; ebp bit 0 = swapped flag
!dec ecx ; size - 1
!bs_loop0:
!mov esi, ecx
!mov edi, edx
!mov eax, [edi]
!bs_loop1:
!add edi, 4
!mov ebx, [edi]
!cmp eax, ebx ; compare array items
!jng bs_no_swap
!xchg eax, ebx ; swap items
!mov [edi], ebx
!mov [edi - 4], eax
!bts ebp, 0 ; set swapped flag
!bs_no_swap:
!mov eax, ebx
!dec esi
!jnz bs_loop1
!dec ecx ; size - 1
!jz bs_exit ; exit if size = 0
!btr ebp, 0 ; test for swapped flag
!jc bs_loop0 ; continue when flag is set
!bs_exit:
!pop esi
!pop edi
!pop ebp
!pop ebx
DisableASM
EndProcedure
[64 bit]
Code: Select all
Procedure bubbleSortASM(Array arr.i(1))
Protected size.i = ArraySize(arr())
Protected base.i = @arr()
EnableASM
mov rcx, size
mov rdx, base
!cmp rcx, 2 ; exit if size < 2
!jl bs_exit
!btr eax, 0 ; eax bit 0 = swapped flag
!dec rcx ; size - 1
!bs_loop0:
!mov r8, rcx
!mov r9, rdx
!mov r10, [r9]
!bs_loop1:
!add r9, 8
!mov r11, [r9]
!cmp r10, r11 ; compare array items
!jng bs_no_swap
!xchg r10, r11 ; swap items
!mov [r9], r11
!mov [r9 - 8], r10
!bts eax, 0 ; set swapped flag
!bs_no_swap:
!mov r10, r11
!dec r8
!jnz bs_loop1
!dec rcx ; size - 1
!jz bs_exit ; exit if size = 0
!btr eax, 0 ; test for swapped flag
!jc bs_loop0 ; continue when flag is set
!bs_exit:
DisableASM
EndProcedure
Re: ...PureBasic 2x slower than Java?
Posted: Tue Nov 15, 2011 11:06 am
by c4s
Danilo wrote:I would be happy if PureBasic would not include unneeded procedures. [...] Does not affect speed, but with many includes and procedures your exe's can become very big because of included dead code.
Yes, this would be great! Honestly I thought this already happens but as it it doesn't work for includes?!
Re: ...PureBasic 2x slower than Java?
Posted: Tue Nov 15, 2011 11:24 am
by Danilo
c4s wrote:Danilo wrote:I would be happy if PureBasic would not include unneeded procedures. [...] Does not affect speed, but with many includes and procedures your exe's can become very big because of included dead code.
Yes, this would be great! Honestly I thought this already happens but as it it doesn't work for includes?!
If your procedures not depend on another procedure, they are not included if not used.
In the following code the procedures are not included:
Code: Select all
Procedure plus(a,b)
ProcedureReturn a+b
EndProcedure
Procedure minus(a,b)
ProcedureReturn a-b
EndProcedure
If a procedure calls another procedure, the another procedure is included:
Code: Select all
Procedure plus(a,b)
ProcedureReturn a+b
EndProcedure
Procedure minus(a,b)
ProcedureReturn a-b
EndProcedure
Procedure add(a,b)
ProcedureReturn plus(a,b)
EndProcedure
Here Procedure plus(a,b) is included in the .exe because it is called from add(),
even if add is not called.
So as soon as 1 procedure calls another one, the called procedure is included.
Thats why 21 procedures unnecessary procedures are included in my gDrawing test,
because some procedures call other procedures in this system.