Jump to content

reassigning the same value to a variable repeatedly


Recommended Posts

Is this better to check a variable before you assign it to a value that could be the same?

for example:

local $EmptyLog = false

func WriteLog($text)
    _guictrledit_appendtext($log, ($EmptyLog ? @CRLF : $empty) & $text)
    If $EmptyLog Then $EmptyLog = False
endfunc

or does AutoIt behind the scenes already check this?

i guess overwriting memory with the same value over and over again is not good if you can prevent this with a check?

Link to comment
Share on other sites

Hi Bilgus,

so basically it's a tiny bit better to do this, but it won't change things dramatically unless you go bigger then a boolean.

i'm a bit obsessive compulsive with sparing my computer some work and it's just interesting to know how stuff works :)

Edited by TheAutomator
Link to comment
Share on other sites

In the end you just caused it extra work because it had to move things around to check the value and then decide to run or jump past run code to set the value

It ends up being less instructions for the PC to set the value blindly..

Its down to counting grains of sand in a desert and in Autoit it probably isn't going to make any difference but in C for instance you just added two or 3 instructions and that makes a noticeable difference in a really tight loop where performance counts

Really unless you have an issue with performance in the end you are probably better off just going with whatever is easiest to read

try something like this

Local $t = TimerInit()
Local $b = True
For $i = 0 to 100000
    If $b = true Then $b = False
Next
ConsoleWrite("T1 " & timerDiff($t) & @CRLF)

Local $t = TimerInit()
For $i = 0 to 100000
    $b = False
Next
ConsoleWrite("T2 " & timerDiff($t) & @CRLF)

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...