Qbasicnews.com

Full Version: How fast is FreeBasic ?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
This code need’s only 0.13 secs to be executed on my pc (1.8 GHz P4) and the exact same code needs above 11 secs compiled with RapidQ. Has anyone made similar tests with other basic compilers?

Regards

Code:
Randomize Timer
Dim start as single
Dim endstart as single
start=timer
Dim Itter as long
Itter=1000000
Dim S(Itter) as double
Dim i as integer
Dim a as double
Dim b as double
For i=1 to Itter
   S(i)=rnd
   a=a+S(i)
   b=b+(S(i))^2
Next i
Print "Mean : ";a/Itter
Print "Variance : ";(Itter*b-a^2)/Itter/(Itter-1)
Print "Sum : ";a
Print "Sum^2 : ";b
endstart=timer
Print
Print "Time(seconds) = ";endstart-start
sleep
Power Basic console compiler takes .046875 seconds to run.

VB 6.0 takes 0.859375 seconds to run (using debug.print for output).


EDIT:

freeBASIC takes .007 (7.8125e-002) seconds to run

Sorry, forgot about actually running the program under FB for a reference point...
.0999756 on mine (alright .10).

1.3GHZ Athlon
Steven Basic:
Could you test also with FB?
This way your results would be more useful...
Just a few tips:

1) put the timer checks right before and after the loop, you are putting it before the dynamic array allocation and after all those PRINT's (console can be quite slow)

2) use a constant for Itter so the array can be a static one, what will gen much better code in both FB and PB

3) use a bigger number of interations, tests running below .1 secs can be imprecise on non-realtime OSes like Windows

The result for the "adaptation" below compiled by FB 0.12 was "Time(seconds) = 0.56152344" on my 1.8 Athlon XP.

Code:
Randomize Timer
Dim start as single
Dim endstart as single
const Itter = 10000000
Dim S(Itter) as double
Dim i as long
Dim a as double
Dim b as double
start=timer
For i=1 to Itter
   S(i)=rnd
   a=a+S(i)
   b=b+(S(i))^2
Next i
endstart=timer
Print "Time(seconds) = ";endstart-start
sleep


The code below compiled with PowerBASIC 7.04 took 1.82 secs:

Code:
#COMPILE EXE
#DIM ALL
deflng a-z
FUNCTION PBMAIN () AS LONG
Dim start as global single
Dim endstart as global single
%Itter = 10000000
Dim S(%Itter) as global double
Dim i as global long
Dim a as global double
Dim b as global double
start=timer
For i=1 to %Itter
   S(i)=rnd
   a=a+S(i)
   b=b+(S(i))^2
Next i
endstart=timer
msgbox str$(endstart-start)
END FUNCTION

I was going to try other BASIC compilers like PureBASIC and XBASIC, but the syntax can be so different that i gave up :P
Damn v1c, you typed that thing about the PRINT locations in the code as I was typing it. There goes my one chance to sound smart! :lol: :lol: :lol: :lol: :lol: :lol:
RapidQ is not a "real" compiler - it produces bytecode, which is executed by its bytecode engine (which is embedded into your executable.) Naturally, it's a bit slower.
Sorry Nek ;)

RapidQ shines when it comes to GUI stuff, but yeah, even its examples have a sieve test with a comment written by RQ's author saying it should not be used for number-crunching.

FB plus easy (and portable) GUI statements done with a wrapper or such and nobody will have how to complain -- where is the fbxl Nek? Gimme! ;)
Thanks for the answers. Looks like FreeBasic is fast enough for me :-).

Looking forward for the GUI Compiler tool.

Off-topic :One strange think that I observed is that if someone wants to access from an outside application a function inside a dll compiled with freebasic he must add a ‘@8’ at the end of this function. ??

Regards
The @ is used by STDCALL procs (that is the default calling convention on Windows for any FB routine), but VB/RQ seem to not mangle the alias' automatically -- do VB/RQ have a STDCALL clause?

You can declare the exported functions as CDECL at FB and VB/RQ, so no @ will be added.. i'm guessing that VB/RQ will add an underscore to the CDECL alias' automatically..
Pages: 1 2