I am writing a UI application which accept an input from the user -
up to 50,000 entries which he pastes to a Textbox
, which I need to convert to List<Uint32>
(Distinct)
In the process, I display the Distict list (the output) in the 'Textbox'.
I am splitting the text and converting it to a Distinct list of Uint32 Then I convert the list to array.
private List<UInt32> ConvertTextToList(string TextBoxText)
{
string[] TextBoxSplitted = TextBoxText.Split(new string[] { Environment.NewLine},StringSplitOptions.RemoveEmptyEntries); //Fast
var TextBoxSplittedAsList = TextBoxSplitted.ToList<string>(); //Fast
List<UInt32> lp = TextBoxSplittedAsList.ConvertAll(new Converter<string, UInt32>(element => Convert.ToUInt32(element))); //Fast
List<UInt32> uintList = lp.Distinct<UInt32>().ToList<UInt32>(); //Fast
UInt32[] uintListArray = uintList.ToArray(); //Fast
//Slow part (measured 15 sec on core2duo 2.53GHz)
StringBuilder builder = new StringBuilder();
Array.ForEach(uintListArray, x => builder.Append(x));
//Done slow part
SomeTextBox.text = builder.ToString();
return uintList;
}
First I tried with - ListOfHeliostatsText.Text = string.Join(",", uintListArray);
Which was slower (about 25% slower than using StringBuilder
)
I feel my function designed wrong, two many conversions.
Is there anyway to improve the performance of this function ?
EDIT: My bad, The slow part is the ListOfHeliostatsText.Text = builder.ToString();
I will continue reading the answers.