Results 1 to 2 of 2

Thread: Hard test: 1 million FOR/NEXT loop

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

    Hard test: 1 million FOR/NEXT loop

    This is an hard one: 1 million FOR/NEXT loop done inside a function.

    [code=thinbasic]
    DIM MaxCount AS LONG value 1000000

    DIM T1 AS DOUBLE
    DIM T2 AS DOUBLE

    DIM Message AS STRING
    Message = "This program will count " & MaxCount & " times.\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

    '---Speed up operations a bit
    doevents(off)

    T1 = TIMER
    Counter
    T2 = TIMER
    MSGBOX 0, "Seconds:" & $tab & $tab & FORMAT$(T2 - T1, "#0.000000")

    function Counter() as long
    Dim i, j as long
    For i = 1 To MaxCount
    INCR j
    Next
    end function
    [/code]

    Try to change Counter function with something different like:
    [code=thinbasic] function Counter() as long
    Dim i, j as long
    For i = 1 To MaxCount
    j = sin(i)
    j = cos(i)
    Next
    end function
    [/code]
    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

  2. #2
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    68
    Posts
    3,865
    Rep Power
    405

    Re: Hard test: 1 million FOR/NEXT loop

    375 ms for the first one.

    1.453 seconds for the second one.
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

Similar Threads

  1. Usage of DO/LOOP, DO WHILE/LOOP, DO / LOOP UNTIL
    By Petr Schreiber in forum Samples for help file
    Replies: 2
    Last Post: 29-05-2007, 16:06

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
  •