...PureBasic 2x slower than Java?

Everything else that doesn't fall into one of the other PB categories.
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: ...PureBasic 2x slower than Java?

Post 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++.
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: ...PureBasic 2x slower than Java?

Post 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. :)
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: ...PureBasic 2x slower than Java?

Post 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.
User avatar
Blood
Enthusiast
Enthusiast
Posts: 161
Joined: Tue Dec 08, 2009 8:34 pm
Location: United Kingdom

Re: ...PureBasic 2x slower than Java?

Post 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!
C provides the infinitely-abusable goto statement, and labels to branch to. Formally, the goto is never necessary, and in practice it is almost always easy to write code without it. We have not used goto in this book. -- K&R (2nd Ed.) : Page 65
User avatar
Kiffi
Addict
Addict
Posts: 1485
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: ...PureBasic 2x slower than Java?

Post by Kiffi »

Blood wrote: Yeah, Java's startup speed is crap but during runtime Java flies!
same as .NET-Applications.

Greetings ... Kiffi
Hygge
User avatar
Blood
Enthusiast
Enthusiast
Posts: 161
Joined: Tue Dec 08, 2009 8:34 pm
Location: United Kingdom

Re: ...PureBasic 2x slower than Java?

Post 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.
C provides the infinitely-abusable goto statement, and labels to branch to. Formally, the goto is never necessary, and in practice it is almost always easy to write code without it. We have not used goto in this book. -- K&R (2nd Ed.) : Page 65
Thorium
Addict
Addict
Posts: 1305
Joined: Sat Aug 15, 2009 6:59 pm

Re: ...PureBasic 2x slower than Java?

Post 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.
Last edited by Thorium on Mon Nov 14, 2011 10:41 pm, edited 1 time in total.
Ramihyn_
Enthusiast
Enthusiast
Posts: 314
Joined: Fri Feb 24, 2006 9:40 am

Re: ...PureBasic 2x slower than Java?

Post by Ramihyn_ »

Better algorithms beat compiler optimization anytime, anyway.
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: ...PureBasic 2x slower than Java?

Post 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.
"Have you tried turning it off and on again ?"
A little PureBasic review
Thorium
Addict
Addict
Posts: 1305
Joined: Sat Aug 15, 2009 6:59 pm

Re: ...PureBasic 2x slower than Java?

Post 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.
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: ...PureBasic 2x slower than Java?

Post 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)
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: ...PureBasic 2x slower than Java?

Post 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.
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: ...PureBasic 2x slower than Java?

Post 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
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: ...PureBasic 2x slower than Java?

Post 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?!
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: ...PureBasic 2x slower than Java?

Post 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.
Last edited by Danilo on Tue Nov 15, 2011 11:26 am, edited 1 time in total.
Post Reply