0

I'm creating a vb.net winforms application that will take in user given strings, parse them, and print out labels with variable information. The given string will be used in all the labels, but the variable part of the string will change with each label.

My question is: is it better to parse the strings one time, then store those values in arrays, or to parse the string each time a label is printed? Which will perform better? Which is better practice? What is the proper way to test something like this?

MAW74656
  • 3,449
  • 21
  • 71
  • 118

2 Answers2

1

Parsing is definitely heavy stuff.

In this particular instance if you do not have any memory constraints then you should parse once and store to speed up your application, especially if it is going to be something that is being used by people :)

Victor Parmar
  • 5,719
  • 6
  • 33
  • 36
  • Memory is not really a problem as we're talking about 3-4 strings tops, each will parse out to be 3 elements. – MAW74656 Mar 16 '11 at 19:06
  • 3-4 strings tops? 3 elements? What exactly is your performance problem? – David Heffernan Mar 16 '11 at 19:08
  • I don't know that there is a problem. Just trying to be efficient and learn good practice at the same time. I know best practice for optimizing is to profile then fix the bad parts, but I thought I would avoid having a bad part in this case. – MAW74656 Mar 16 '11 at 19:09
1

If saving data in memory is done for performance, my preference would be not to do it until I knew the parsing was actually a performance problem, which I detect by random-pausing.

Generally my rule of thumb is - the less data structure the better. If you have data structure you have to worry about it getting stale, and any time you change the program you have more code to modify and put bugs into.

Besides, parsing does not need to be slow, especially compared to whatever else you're doing.

Community
  • 1
  • 1
Mike Dunlavey
  • 40,059
  • 14
  • 91
  • 135