TheAutomator Posted March 22, 2018 Posted March 22, 2018 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? Retro Console, NestedArrayDisplay UDF foldermaker-pro-clone MiniMark Editor
Bilgus Posted March 22, 2018 Posted March 22, 2018 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.)
TheAutomator Posted March 22, 2018 Author Posted March 22, 2018 (edited) 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 March 22, 2018 by TheAutomator Retro Console, NestedArrayDisplay UDF foldermaker-pro-clone MiniMark Editor
Bilgus Posted March 22, 2018 Posted March 22, 2018 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) Earthshine and TheAutomator 2
Earthshine Posted March 22, 2018 Posted March 22, 2018 (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 March 22, 2018 by Earthshine My resources are limited. You must ask the right questions
Bilgus Posted March 22, 2018 Posted March 22, 2018 Now try this Local $t = TimerInit() Local $n = 0 For $i = 0 to 100000 If $n = 0 then $n += 1 - 5 + 4 - 3 * 2 Next ConsoleWrite("T1 " & timerDiff($t) & @CRLF) Local $t = TimerInit() For $i = 0 to 100000 $n += 1 - 5 + 4 - 3 * 2 Next ConsoleWrite("T2 " & timerDiff($t) & @CRLF) Notice how T1 is now the fastest?
TheAutomator Posted March 22, 2018 Author Posted March 22, 2018 I see, yes you are right Thanks for explaining Bilgus! Retro Console, NestedArrayDisplay UDF foldermaker-pro-clone MiniMark Editor
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now