Found Little Speed Test On The Net

Everything else that doesn't fall into one of the other PB categories.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Franco.

Hi fellas,
after reading some really negative topics on this forum I want to share some positive thoughts

Yesterday I found test code for different programming languages, mostly basic @:

http://electronicauy.8bit.co.uk

So I wanted to know where PureBasic stays and converted the code to Pure.
On my machine (Duron 950Mhz Sony Notebook) I had the following result:
Visual Basic EXE = 12s
BCX Basic EXE = 6s ;this is basic code translated to C and compiled with LCC-Win32
PureBasic EXE = 2.3s ; :)
PureBasic with enabled Debugger (F5 in Editor) = 3s
Pascal EXE = 6s
Didn't test the other ones...

Well I don't know how 'good' the test code is (in general) but I had a good feeling after processing the tests.

On faster machines you get shorter times, so for a real comparison you need to start all EXE's on your computer. (on the website)

The only negative thing I found was, the BCX/LCC-Win32 EXE file is 8kb small and the PureBasic EXE 18kb.
But on the other hand, all the other EXE's are bigger :)


For the ones of you that are interested in the translated Pure code:

Code: Select all

OpenWindow(1,224, 172, 205, 64,#PB_Window_SystemMenu,"Test Speed PureBasic")
CreateGadgetList(WindowID()) 
StringGadget(1,  4, 4, 128, 20, "") 
ButtonGadget(2, 136, 4, 60, 20, "Begin") 
TextGadget(3,4, 28, 128, 16, "Elapsed: 0") 
ButtonGadget(4, 136, 28, 60, 20, "Exit") 

  Repeat
    EventID.l = WaitWindowEvent()
    Select EventGadgetID() 
      Case 2
        Gosub ExecuteTest
      Case 4
        End
    EndSelect
  Until EventID = #PB_EventCloseWindow

End

ExecuteTest:

    SetGadgetText(3, "Please Wait .")
    
  StartTimer.l = GetTickCount_()
    
  For LoopFor1.l = 1 To 10000000
    Result1.f=((100000 * 100) / 1000) + Sqr(4)
    Result2.f=((100000 * 100) / 1000) + Sqr(4)
    Result3.f=((100000 * 100) / 1000) + Sqr(4)
    Result4.f=((100000 * 100) / 1000) + Sqr(4)
  
    Result1=((100000 * 100) / 1000) + Sqr(4)
    Result2=((100000 * 100) / 1000) + Sqr(4)
    Result3=((100000 * 100) / 1000) + Sqr(4)
    Result4=((100000 * 100) / 1000) + Sqr(4)
  
    If LoopFor1 = 100000
      SetGadgetText(3, "Please Wait .") 
    ElseIf LoopFor1 = 1000000
      SetGadgetText(3, "Please Wait .") 
    ElseIf LoopFor1 = 10000000
      SetGadgetText(3, "Please Wait .") 
    EndIf
  Next LoopFor1
  
  SetGadgetText(1, "Result:" + Str(Result1 + Result2))
     
  ElapsedTime.l = GetTickCount_()-StartTimer

  SetGadgetText(3, "Elapsed: " + Str(ElapsedTime) +  " ms")

Return
Have a nice day...

Franco
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Justin.

PB can beat the size, with an api window compiles in 7.5 kb. using an api dialog should be even smaller.

Code: Select all

msg.MSG
wc.WNDCLASSEX

hinst=GetModuleHandle_(0)
classname$="mywndpbclass003"

procedure ExecuteTest()
  shared hwed,hwst
  sendmessage_(hwst,#WM_SETTEXT,0,"Please Wait .")
    
  StartTimer.l = GetTickCount_()
    
  For LoopFor1.l = 1 To 10000000
    Result1.f=((100000 * 100) / 1000) + Sqr(4)
    Result2.f=((100000 * 100) / 1000) + Sqr(4)
    Result3.f=((100000 * 100) / 1000) + Sqr(4)
    Result4.f=((100000 * 100) / 1000) + Sqr(4)
  
    Result1=((100000 * 100) / 1000) + Sqr(4)
    Result2=((100000 * 100) / 1000) + Sqr(4)
    Result3=((100000 * 100) / 1000) + Sqr(4)
    Result4=((100000 * 100) / 1000) + Sqr(4)
  
    If LoopFor1 = 100000
      sendmessage_(hwst,#WM_SETTEXT,0,"Please Wait .")
    ElseIf LoopFor1 = 1000000
      sendmessage_(hwst,#WM_SETTEXT,0,"Please Wait .")
    ElseIf LoopFor1 = 10000000
      sendmessage_(hwst,#WM_SETTEXT,0,"Please Wait .")
    EndIf
  Next LoopFor1
  
  sendmessage_(hwed,#WM_SETTEXT,0,"Result:" + Str(Result1 + Result2))
   
  ElapsedTime.l = GetTickCount_()-StartTimer

  sendmessage_(hwst,#WM_SETTEXT,0,"Elapsed: " + Str(ElapsedTime) +  " ms")
endprocedure

procedure windowproc(hwnd,msg,wparam,lparam)
select msg
  case #WM_COMMAND
    select wparam
      case 2
        ExecuteTest()
        
      case 4
        PostQuitMessage_(0)
    endselect
    retval=0

  case #WM_CLOSE
    PostQuitMessage_(0)
    retval=0

  default
    fakeendselect : procedurereturn DefWindowProc_(hwnd,msg,wparam,lparam)
endselect
procedurereturn retval
endprocedure

wc\cbSize=SizeOf(WNDCLASSEX)
wc\style=#CS_HREDRAW|#CS_VREDRAW
wc\lpfnWndProc=@windowproc()
wc\cbClsExtra=0
wc\cbWndExtra=0
wc\hInstance=hinst
wc\hIcon=0
wc\hCursor=LoadCursor_(#NULL,#IDC_ARROW)
wc\hbrBackground=GetSysColorBrush_(#COLOR_MENU)
wc\lpszMenuName=#NULL
wc\lpszClassName=@classname$
wc\hIconSm=0

RegisterClassEx_(@wc)

hwmain=CreateWindowEx_(0,classname$,"Test Speed PureBasic",#WS_SYSMENU,224,172,205,90,0,#null,hinst,0)
hwed=CreateWindowEx_(#WS_EX_CLIENTEDGE,"Edit","",#WS_CHILD|#WS_VISIBLE,4,4,128,20,hwmain,1,hinst,0)
hwbt1=CreateWindowEx_(0,"Button","Begin",#WS_CHILD|#WS_VISIBLE|#BS_PUSHBUTTON,136,4,60,20,hwmain,2,hinst,0)
hwst=CreateWindowEx_(0,"Static","Elapsed: 0",#WS_CHILD|#WS_VISIBLE,4,28,128,16,hwmain,3,hinst,0)
hwbt2=CreateWindowEx_(0,"Button","Exit",#WS_CHILD|#WS_VISIBLE|#BS_PUSHBUTTON,136,28,60,20,hwmain,4,hinst,0)

ShowWindow_(hwmain,#SW_SHOWNORMAL)
UpdateWindow_(hwmain)

while GetMessage_(@msg,#null,0,0)
  TranslateMessage_(@msg)
  DispatchMessage_(@msg)
wend

BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by koehler.



Hmm, having a discussion on another board, and it seems folks don't believe PB is as fast as C++. Now, I thought that was what I heard, wasn't it?

Either way, anyone with any decent C++ vs PB examples?

If it is not as fast as C++, thats fine. However, if it is then I would love to find out if that is really true.



--
1980 Applesoft Basic, '81 6502 Assembler, '82 Pascal, '96 C, '00 Blitz Basic
2003 Pure Basic - History does repeat itself.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fred.

Depending on what you compare. On the commandset, PB is faster than C++ (using specialized commands). On the generated code, there is some cases where C++ is faster, especially in array and loop. Thanks to a very good optimizer and instructions scheduler. But PB is going closer at every new release. BTW, comparing PB to the state of the art MS Visual C++ compiler seems a bit odd..
Post Reply