Results 1 to 4 of 4

Thread: Different loops type. Speed test script

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,818
    Rep Power
    10

    Different loops type. Speed test script

    How fast are thinBasic loops? Here the answer.

     '-----------------------------------------------------------------------------
     'Variable declaration
     '-----------------------------------------------------------------------------
     Dim T0, T1, T2, T3, T4, T9 AS quad
    
     DIM MaxLoops  AS LONG VALUE 100000
     DIM Count   AS LONG
     DIM tmpNumber AS QUAD
     DIM tmpString AS STRING
     DIM Message  AS STRING
     DIM tFormat  AS STRING VALUE "#0"
    
     '-----------------------------------------------------------------------------
     'Confirm script execution
     '-----------------------------------------------------------------------------
     Message = "This program will perform:\n"
     Message += "" & MaxLoops & " FOR\n"
     Message += "" & MaxLoops & " WHILE/WEND\n"
     Message += "" & MaxLoops & " DO/LOOP WHILE\n"
     Message += "" & MaxLoops & " DO/LOOP UNTIL\n"
     Message += "Please press Yes to go on, NO to Stop\n"
    
     DIM lResult AS LONG = MSGBOX(0, Message, %MB_YESNO, "Continue?") 
     IF lResult <> %IDYES THEN
      STOP
     END IF
    
     T0 = GetTickCount
     
     '-----------------------------------------------------------------------------
     'Test speed: FOR loop
     '-----------------------------------------------------------------------------
     T1 = GetTickCount
     tmpNumber = 2
     FOR Count = 1 TO MaxLoops
      tmpNumber += 1
      tmpNumber = (tmpNumber * 2) ^ 2
      tmpNumber = 2
     NEXT
     
     '-----------------------------------------------------------------------------
     'Test speed: WHILE loop
     '-----------------------------------------------------------------------------
     T2 = GetTickCount
     Count = 0
     tmpString = ""
     tmpNumber = 2
     WHILE Count < MaxLoops
      Count += 1
      tmpNumber = (tmpNumber * 2) ^ 2
      tmpNumber = 2
     WEND
     
     '-----------------------------------------------------------------------------
     'Test speed: DO loop WHILE
     '-----------------------------------------------------------------------------
     T3 = GetTickCount
     Count = 0
     tmpString = ""
     tmpNumber = 2
     DO
      Count += 1
      tmpNumber = (tmpNumber * 2) ^ 2
      tmpNumber = 2
     LOOP WHILE Count < MaxLoops
    
     '-----------------------------------------------------------------------------
     'Test speed: DO loop UNTIL
     '-----------------------------------------------------------------------------
     T4 = GetTickCount
     Count = 0
     tmpString = ""
     tmpNumber = 2
     DO
      Count += 1
      tmpNumber = (tmpNumber * 2) ^ 2
      tmpNumber = 2
     LOOP UNTIL Count >= MaxLoops
    
     T9 = GetTickCount
     
     '-----------------------------------------------------------------------------
     'Show results with some internal counters
     '-----------------------------------------------------------------------------
     Message = "Test " & MaxLoops & " loops." & $CRLF
     Message += MaxLoops & " FOR"    & $tab & FORMAT$(T2 - T1, tFormat)      & " msec." & $CRLF
     Message += MaxLoops & " WHILE"   & $tab & FORMAT$(T3 - T2, tFormat)      & " msec." & $CRLF 
     Message += MaxLoops & " DO WHILE" & $tab & FORMAT$(T4 - T3, tFormat)      & " msec." & $CRLF
     Message += MaxLoops & " DO UNTIL" & $tab & FORMAT$(T9 - T4, tFormat)      & " msec." & $CRLF
     Message += "Total    "     & $tab & FORMAT$(T9 - T0, tFormat)      & " msec." & $CRLF
     Message += "Final message"     & $tab & FORMAT$(GetTickCount - T9, tFormat) & " msec." & $CRLF
    
     MSGBOX(0, Message)
    
    Last edited by ErosOlmi; 08-02-2024 at 19:48.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

Similar Threads

  1. NEO speed test result
    By kryton9 in forum thinBasic General
    Replies: 9
    Last Post: 02-05-2007, 20:44

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •