Jump to content

Recommended Posts

Posted

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?

Posted

Generally it is cheaper to overwrite than to check first

The only time that would change is if there are a lot of calculations that need performed to come up with the value or larger datatypes (arrays etc.)

Posted

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)

 

Posted (edited)

yep, you are causing more work by checking, i would not agree that what you are doing is any better. just more cycles.

Edited by Earthshine

My resources are limited. You must ask the right questions

 

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
×
×
  • Create New...