public void Test_ConvertingToString(SeparatedLine input, string result) { //checks ToString Assert.True(input.ToString() == result); //checks explicit converter Assert.True((string)input == result); }
private static IEnumerable <string> FetchData(Random rnd, IReadOnlyDictionary <int, char[]> dictionary, int count, int newLineSize) { //var sb = new StringBuilder(); //slower for 1Gb file: ~14.6s for StringBuilder, string line by line - ~14.06s //var newLine = $"{rnd.Next(0, int.MaxValue)}. {new string(dictionary[rnd.Next(0, count)])}"; //allocates ~3Gb (but less, than SB - ~4Gb) //even with buffer //Encoding.ASCII.GetByteCount(newLine) - slower than newLine.Length //We'll assume that in dictionaries we will be within ASCII symbols (in ASCII 1 char == 1 byte) while (_resultFileSize > 0) { //for 1Gb file: 9.422s with that, allocates ~3Gb, but faster because of operations on stack var separatedLine = new SeparatedLine { Number = rnd.Next(0, int.MaxValue), Text = dictionary[rnd.Next(0, count)] }; _resultFileSize -= newLineSize + separatedLine.GetLength(); yield return(separatedLine.ToString()); } }