Author Topic: Small calc optimizations  (Read 7587 times)

Offline Quentin

  • Prof. Inline
  • *****
  • Posts: 902
    • View Profile
Re: Small calc optimizations
« Reply #15 on: 2008-Aug-16 »
@ale870
could you please explain how you did the tests to say MOD is faster than using IF. Because if couldn't believe it ;)
I did a simple test with the following coding and IF is always much faster. (10,000,000 iterations so it takes some millisecs)

Code: GLBasic [Select]
LOCAL count = 10000000
LOCAL counter, i
LOCAL diff1, diff2, time1, time2

time1 = GETTIMERALL()
FOR i = 1 TO count
        INC counter, 1
        IF counter >= 360 THEN counter = 0
NEXT
diff1 = GETTIMERALL() - time1

time2 = GETTIMERALL()
FOR i = 1 TO count
        INC counter, 1
        counter = MOD(counter, 360)
NEXT
diff2 = GETTIMERALL() - time2

PRINT "IF-Statement: " + diff1, 0, 0
PRINT "MOD-Statement:" + diff2, 0, 40
SHOWSCREEN
MOUSEWAIT