' asm_benchmark.pb — Assembly-level benchmark simulation
#COMPILE EXE
#DIM ALL

FUNCTION PBMAIN() AS LONG
    LOCAL intAddTime AS DOUBLE
    LOCAL intMulTime AS DOUBLE
    LOCAL floatAddTime AS DOUBLE
    LOCAL floatMulTime AS DOUBLE
    LOCAL memCopyTime AS DOUBLE
    LOCAL i AS LONG
    LOCAL j AS LONG
    LOCAL k AS LONG
    LOCAL intResult AS LONG
    LOCAL intA AS LONG
    LOCAL intB AS LONG
    LOCAL intC AS LONG
    LOCAL floatResult AS DOUBLE
    LOCAL floatA AS DOUBLE
    LOCAL floatB AS DOUBLE
    LOCAL numIterations AS LONG
    LOCAL iter AS LONG
    LOCAL totalTime AS DOUBLE
    LOCAL memBuf(1000) AS LONG
    LOCAL memBuf2(1000) AS LONG
    LOCAL copyVal AS LONG

    numIterations = 5000

    PRINT "=== Assembly Benchmark Simulation ==="
    PRINT "Iterations: " + STR$(numIterations)

    PRINT "Integer ADD benchmark..."
    intResult = 0
    FOR i = 1 TO numIterations
        intResult = intResult + 1
    NEXT i
    intAddTime = numIterations
    PRINT "  " + STR$(numIterations) + " adds: result=" + STR$(intResult)

    PRINT "Integer MUL benchmark..."
    intResult = 1
    FOR i = 1 TO 100
        intResult = intResult * 2
    NEXT i
    intMulTime = 100
    PRINT "  " + "100 muls: result=" + STR$(intResult)

    PRINT "Float ADD benchmark..."
    floatResult = 0
    FOR i = 1 TO numIterations
        floatResult = floatResult + 1.0
    NEXT i
    floatAddTime = numIterations
    PRINT "  " + STR$(numIterations) + " fadds: result=" + STR$(floatResult)

    PRINT "Float MUL benchmark..."
    floatResult = 1.0
    FOR i = 1 TO 100
        floatResult = floatResult * 1.01
    NEXT i
    floatMulTime = 100
    PRINT "  " + "100 fmuls: result=" + STR$(floatResult)

    PRINT "Memory copy benchmark..."
    FOR i = 0 TO 999
        memBuf(i) = i
    NEXT i
    FOR k = 1 TO 100
        FOR i = 0 TO 999
            memBuf2(i) = memBuf(i)
        NEXT i
    NEXT k
    memCopyTime = 100
    PRINT "  " + "100 copies of 1000 elements done"

    PRINT "--- Results ---"
    PRINT "Integer add: " + STR$(intAddTime) + " ops"
    PRINT "Integer mul: " + STR$(intMulTime) + " ops"
    PRINT "Float add: " + STR$(floatAddTime) + " ops"
    PRINT "Float mul: " + STR$(floatMulTime) + " ops"
    PRINT "Memory copy: " + STR$(memCopyTime) + " blocks"
    PRINT "=== End Benchmark ==="
    FUNCTION = 0
END FUNCTION
