Reputation: 141
Alright, so a little bit of context: I'm dealing with some 3D wireframe objects (walls with windows defined by their corner points), stored in a csv file. There is about 2000 entry points stored in the csv file I'm using as an example, which is 8 walls and close to 500 windows.
The ultimate goal I'm aiming for is to have all that data stored into x lists of coplanar lines.
in order to get the lines from the points, I just match the points two by two and make sure that I'm not dealing with the diagonal of a window, and then I add that line to a list.
This part is figured out and works well, but I'm wondering what is more efficient/considered best practice from then on :
Is it better to first get all the lines into a big list, and then sort them out into x lists of coplanar lines, or is it better to directly sort them into the x lists as I loop through the points to create the lines ?
The first case seems more legible to me, but could be slower as it means looping through all the lines while the second case would deal with that as the lines are created, but I can see it be more prone to failure too.
Disclaimer: I am a self-taught scripter, so what may seem obvious to you may not be to me. Don't be afraid to explain basic things about good practices, it can only help me get better!
Upvotes: 1
Views: 143
Reputation: 163612
Usually, it's best to only parse something once. There can be a great deal of overhead in reading large text files and turning them into real data. If you use that data over and over again, there's no reason to parse it over and over again.
In your case, a few thousand lines of CSV isn't much to deal with. I'd echo @AndrewMorton's comment... if what you're doing works reliably and you understand it, it's fine to stick with what you've already implemented. After all, working software is the goal, and few people are going to care if it takes 100 milliseconds to load that data, vs. 25 milliseconds. But they will definitely care if the complexity goes up potentially causing you bugs and headache.
Upvotes: 2