Jump to content

Recommended Posts

Posted

Ok, I am genuinely confused by this. I'm using GDI Plus to draw images to the screen and then "moving" the images by redrawing them in GDI+.

But the problem is that the script slows depending on how I define my initial variables and I don't see why -

Like this, it's a useable script, reasonably fast and responsive ("local" here is the global scope, so I don't think memory is the problem)

Local Const $Width = 700
Local Const $Height = 650
Local Const $fog = 8
Local Const $n_blocks = 30
Local Const $tilt = $Pi/5
Local Const $bgcolor = "F0506070"
Local $dot_distance = 50

But like this and the whole script becomes around 3 seconds slower for every action

Switch $split[1]
  Case "fog"
   Global Const $fog = 8
  Case "n_blocks"
   Global Const $n_blocks = 30
  Case "bgcolor"
   Global Const $bgcolor = "F0506070"
  Case "sphere_image"
   Global $sphere_image = @ScriptDir & "\images\sphere.gif"
  Case "sphereR0"
   Global $sphereR0 = 255
  Case "sphereG0"
   Global $sphereG0 = 255
  Case "sphereB0"
   Global $sphereB0 = 90
EndSwitch

And, of course, I wanted to use the latter. Any ideas what I can do?

Posted

Why not declare the variables at the top of the script and then change their values? Try and let me know. I also tend not to use Const unless I have to. Plus is this in a Function, because it would be best to use Local.

Global $fog, $n_blocks, $bgcolor, $sphere_image, $sphereR0, $sphereG0, $sphereB0

Switch $split[1]
  Case "fog"
   $fog = 8
  Case "n_blocks"
   $n_blocks = 30
  Case "bgcolor"
   $bgcolor = "F0506070"
  Case "sphere_image"
   $sphere_image = @ScriptDir & "\images\sphere.gif"
  Case "sphereR0"
   $sphereR0 = 255
  Case "sphereG0"
   $sphereG0 = 255
  Case "sphereB0"
   $sphereB0 = 90
EndSwitch

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Posted

That doesn't seem to have made a difference. The variable $split[1] comes from a FileReadLine() and the file is closed after the Switch loop, would this make a difference? And Info, I'll bear that in mind - how long is long?

Thanks for the help guys.

Posted

I think I've found a solution. First I shortened some of my longer variables (this is surprising news!) and that made a small difference, BUT then I realised that because I was taking some variables from an external file, they were all being read as string type, so in expressions such as "If $var Then" later on, even if $var was "False" then the code was executed. This made a huge difference - it cut down the average time for one of my functions from 250ms to 79ms (according to timerdiff)...

Now I know to make sure my variables are of the right type in future. Thanks for the tips though, I'll bear all of it in mind for future scripts.

Posted

You shouldn't shorten variable names because it is faster. Readability is a lot more important than optimization. Beside that, we can write a preprocessor which will shorten all variable names for you (like obfuscator does) so that your script executes faster.

Posted

You shouldn't shorten variable names because it is faster. Readability is a lot more important than optimization. Beside that, we can write a preprocessor which will shorten all variable names for you (like obfuscator does) so that your script executes faster.

Fully aknowledged, you should better use

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...