corrado33 Posted June 4, 2018 Share Posted June 4, 2018 Hi, I have a script where I have to deal with a couple thousand pairs of strings. Currently, I'm storing the two strings in two arrays (because 2d arrays are a pain). However, I've noticed a few things. The script slows down once I've stored ~500 pairs of strings in the array. At least, I THINK that's why the script slows down. So I'm debating offloading the strings to a file every 200 strings or so, but I want to find the fastest way to write them to a file. Would it be quicker to use "FileWriteLine" or "_FileWriteFromArray"? Obviously with "FileWriteLine" I'd have to loop through the array. I debated doing "FileWriteLine" EVERY iteration of my main loop, but that REALLY slowed things down. I know this seems petty, but I'm using this script to analyze a 1,000,000 line file... so efficiency is key. Link to comment Share on other sites More sharing options...
BigDaddyO Posted June 4, 2018 Share Posted June 4, 2018 How long are these strings? You really should look into 2D arrays more as they are extremely useful. I usually try to remember 2D arrays as they would show in a spreadsheet: $Array2D[row][column] best way to speed up the FileWite is to make sure you do a FileOpen instead of specifying the filename in the FileWrite. Link to comment Share on other sites More sharing options...
Earthshine Posted June 4, 2018 Share Posted June 4, 2018 (edited) oops Edited June 4, 2018 by Earthshine My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
corrado33 Posted June 4, 2018 Author Share Posted June 4, 2018 10 minutes ago, BigDaddyO said: How long are these strings? You really should look into 2D arrays more as they are extremely useful. I usually try to remember 2D arrays as they would show in a spreadsheet: $Array2D[row][column] best way to speed up the FileWite is to make sure you do a FileOpen instead of specifying the filename in the FileWrite. I suppose you're right. I just tend to avoid 2d arrays since most languages handle them slightly differently and I don't feel like dealing with syntax. As for string length, the first is ~5 chars, the 2nd is a full file path on a unix system about... 10 folders deep. So ~100+ chars And yes, I learned the FileOpen trick! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 4, 2018 Moderators Share Posted June 4, 2018 corrado33, Are you using ReDim on every pass to resize the arrays? If so then I am not surprised that your script slows down after 500 or so entries. The trick is to initially declare the array at a some intermediate size and then double it whenever it gets full - look at the final example in the Recursion tutorial in the Wiki to see it in action. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
corrado33 Posted June 4, 2018 Author Share Posted June 4, 2018 55 minutes ago, Melba23 said: corrado33, Are you using ReDim on every pass to resize the arrays? If so then I am not surprised that your script slows down after 500 or so entries. The trick is to initially declare the array at a some intermediate size and then double it whenever it gets full - look at the final example in the Recursion tutorial in the Wiki to see it in action. M23 Interesting. Is it significantly slower simply to dimension the array to something greater than I'll ever have? Currently the script is only working on ~2000 pairs of data, so I dimensioned the array to 3000 (more than it'll ever need) then at the end I remove the null entries. Would it be quicker to do what you're doing? Also I did just change the script to read in the massive file (1 million lines) to an array and that exponentially sped up the processing speed of the script. (To the point where I don't even have to worry about this question anymore.) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 4, 2018 Moderators Share Posted June 4, 2018 corrado33, Every ReDim slows down the script, so having none at all is bound to be faster. However, unless you are absolutely sure that you will never exceed the initial array size, I would suggest not hard coding the maximum size when declaring the array and using a dynamic resize as indicated in the example I showed you. M23 Bilgus 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
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