Guidance
指路人
g.yi.org
software / rapidq / Examples / Console / sieve / sieve.bas

Register 
新用户注册
Search 搜索
首页 
Home Home
Software
Upload

  
' Sieve of eratosthenes Benchmark, with a cheap trick, but hey, got to
' use what's available to you!
' Just to prove that you shouldn't use Rapid-Q for math intensive programs

     DIM Flags(8190) AS SHORT
     DIM Iter AS SHORT
     DIM I AS SHORT
     DIM Count AS SHORT
     DIM K AS SHORT
     DIM Prime AS SHORT

     PRINT "Sieve - 10 iterations"

     FOR I = 0 TO 8190
      Flags(I) = 1
     NEXT I

     DIM M AS QMEMORYSTREAM
     M.SaveArray(Flags(0), 8191)   '' Cheap trick

     FOR Iter = 1 TO 10
      Count = 0
      T! = TIMER

      FOR I = 0 TO 8190
       IF Flags(I) = 1 THEN
        Prime = I + I
        Prime = Prime + 3
        K = I + Prime
        WHILE K <= 8190
         Flags(K) = 0
         K = K + Prime
        WEND
        Count = Count + 1
       END IF
      NEXT I
      PRINT "Iteration "; Iter; ": took "; TIMER - T!; " seconds."

      M.Position = 0
      M.LoadArray(Flags(0), 8191)   '' Reinitialize array, cheap trick
     NEXT Iter

掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Wed 2019-7-17  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2013-06-19 07:43:30