' Math Benchmark — CPU performance test with TIMER
#COMPILE EXE
#DIM ALL

FUNCTION PBMAIN() AS LONG
    LOCAL i AS LONG
    LOCAL j AS LONG
    LOCAL x AS DOUBLE
    LOCAL start! AS DOUBLE
    LOCAL elapsed AS DOUBLE

    PRINT "Math Benchmark"
    PRINT STRING$(40, 45)

    start! = TIMER
    FOR i = 1 TO 100000
        x = x + 1.0
    NEXT i
    elapsed = TIMER - start!
    PRINT "Integer add x100000: "; FORMAT$(elapsed, "0.000"); " sec"

    start! = TIMER
    FOR i = 1 TO 100000
        x = x * 1.0001
    NEXT i
    elapsed = TIMER - start!
    PRINT "Float mul x100000: "; FORMAT$(elapsed, "0.000"); " sec"

    start! = TIMER
    FOR i = 1 TO 10000
        FOR j = 1 TO 10000
        NEXT j
    NEXT i
    elapsed = TIMER - start!
    PRINT "Nested loop x10000: "; FORMAT$(elapsed, "0.000"); " sec"

    PRINT STRING$(40, 45)
    PRINT "Benchmark complete"

    FUNCTION = 0
END FUNCTION
