wow... fast....

BlitzMax Forums/BlitzMax Beginners Area/wow... fast....

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

I ran a sieve speed test in PureBasic and BlitzMax. Although PureBasic is renowned for its tight code and speed Max came out on top being roughly 2.5 times quicker.

BlitzMax source
' BlitzMax sieve test

Framework brl.blitz
Import brl.standardio
Import brl.system

Const ITERATIONS=10000

Print("SIEVE OF ERATOSTHENES - "+ITERATIONS+" iterations")
Print ""

Global t=MilliSecs()

For Local Iter = 1 To ITERATIONS

	Local flags[8191],i,k,prime
	Local Count = 0

	For i = 0 To 8190
    	flags[i] = 1
	Next

	For i = 0 To 8190
		If flags[i]=1
			prime=i+i
			prime=prime+3
			k=i+prime
			While k <= 8190
				flags[k] = 0
				k=k+prime
			Wend
			count=count+1
		EndIf
	Next

	FlushMem

Next

t=MilliSecs()-t
Print ITERATIONS+" iterations took "+t+" m/secs."
Print ""
Print "Primes: "+Count

End


PureBasic source
; Ported from another Basic For benchmarking purposes...
; PureBasic version

OpenConsole()

#ITERATIONS=10000

Dim Flags(8191)
Print("SIEVE OF ERATOSTHENES - "+Str(#ITERATIONS)+" iterations")
ConsoleLocate(0,2)

t=GetTickCount_()

For Iter = 1 To #ITERATIONS

  Count = 0

  For I = 0 To 8190
    Flags(I) = 1
  Next

  For I = 0 To 8190
    If Flags(I)=1
       Prime = I + I
       Prime = Prime + 3
       K = I + Prime
       While K <= 8190
         Flags(K) = 0
         K = K + Prime
       Wend
       Count = Count + 1
    EndIf
  Next

Next

t=GetTickCount_()-t
Print(Str(#ITERATIONS)+" iterations took "+Str(t)+" m/secs.")
ConsoleLocate(0,3)
Print("Primes: "+Str(Count))

Delay(3000)
End
; ExecutableFormat=Windows
; CursorPosition=5
; FirstLine=1
; DisableDebugger
; EOF