GLBasic forum

Main forum => GLBasic - en => Topic started by: kaiserpc on 2011-Mar-31

Title: use INC or var = var + val?
Post by: kaiserpc on 2011-Mar-31
Hi,

just wondering if using INC or DEC is any faster/slower than using "variable1 = variable1 + value"?  Or is it just to save you typing extra characters?
Title: Re: use INC or var = var + val?
Post by: kaiserpc on 2011-Mar-31
okay, being a complete newbie in glbasic - do you have a standard test stub you use for testing stuff like this? 

Is there some sort of time counter in GLbasic or would you do it per draw cycle?  So you would see which one would have increased the most INC or var = var + 1 after say 1 minute.  Sorry, just downloaded GLBasic and only started using it.
Title: Re: use INC or var = var + val?
Post by: Ian Price on 2011-Mar-31
Code (glbasic) Select

LOCAL time1#
LOCAL time2#
LOCAL x

time1#=GETTIMERALL()

// Main loop
WHILE x<100

INC x

//x=x+1

PRINT x,10,10

SHOWSCREEN

WEND


time2#=GETTIMERALL()

// Display result (end-time-start-time)
PRINT time2#-time1#,10,10

SHOWSCREEN

KEYWAIT



That is just a vey quick way to test. Increasing x in "WHILE X<100" would give a more accurate reading over a longer period of time.
Title: Re: use INC or var = var + val?
Post by: Minion on 2011-Mar-31
Wouldn`t having the showscreen and print in the main counting loop redner the test pointless ?

Just tried that test (without SHOWSCREEN and PRINT) for x<1000000 and the results where

INC x  -  1.2 seconds

x=x+1  - 3.4 seconds

Thats just my machine, but it looks pretty conclusive to me.
Title: Re: use INC or var = var + val?
Post by: kaiserpc on 2011-Mar-31
cool guys, just what I was after - thx :-)
Title: Re: use INC or var = var + val?
Post by: Ian Price on 2011-Mar-31
QuoteWouldn`t having the showscreen and print in the main counting loop redner the test pointless ?
No, GETTIMERALL() shows the elapsed time since the program's start in 1/1000 sec.

GETTIMER() shows the time since the last SHOWSCREEN.

This allows the user to see the value of X (rather than seeing a blank screen and wondering how long to go, or if the app has crashed). If you try to do too much without SHOWSCREEN, the app will freeze and die.

Remember it's only going to show the difference between the INC or VAR+VAR, as nothing else changes anyway, so the use of PRINT and SHOWSCREEN is perfectly valid.
Title: Re: use INC or var = var + val?
Post by: Minion on 2011-Mar-31
OK, can see where you`re coming from with that, but I still get spurious results whichever I use (and Im guessing you didnt mean to use GETTIMERALL at the end then)
Title: Re: use INC or var = var + val?
Post by: Ian Price on 2011-Mar-31
QuoteIm guessing you didnt mean to use GETTIMERALL at the end then
Yes I did. Using GETTIMER() at the end will only give the result of the time since the last SHOWSCREEN and not a test of the total time taken for the test (end-start times).
Title: Re: use INC or var = var + val?
Post by: Kitty Hello on 2011-Mar-31
INC x in C++ is: "++x" -> one operation

x=x+1: push x, push 1, add, pop x -> a lot more operations.