c# - How do I improve the performance of code using DateTime.ToString? -
:
LoginTree Time. Toastring ("DD.MM.IHH: mm: SS: FFF")
Takes 33% of the total processing time. Does anyone have any idea about how to make it faster?
Edit: This app is used to process some binary logs and it currently takes up to 15 hours to run. So the time of 1/3 will be 5 hours.
EDIT: The application I'm using for profiling is processing approximately 17 GB of binary logs.
It is unfortunate that there is no type of .NET "formatter" type that can parse a pattern And can remember it.
If you are always using the same format, then you really want to hand-craft the formator to do this. Some on the lines of:
public static string formatDetermission (datetime DT) {four [] characters = new colors [21]; Write2Chars (letters, 0, dt.day); Characters [2] = '.'; Write2Chars (letters, 3, dt.Month); Characters [5] = '.'; Write2Chars (character, 6, dt.Year% 100); Character [8] = ''; Write2Chars (letters, 9, dt.Hour); Character [11] = ''; Write2Chars (letters, 12, dt.Minute); Character [14] = ''; Write2Chars (letters, 15, dt.Second); Characters [17] = ''; Write2Chars (Characters, 18, DT. Milyscand / 10); Character [20] = number (dt. millisecond% 10); Return new string (character); } Private static zero Write2Chars (four [] characters, int offset, int value) {character [offset] = digitally (value / 10); Character [offset + 1] = number (value% 10); } Private static four digit (integer value) {return (four) (value + '0'); }
It is very ugly, but perhaps it is very efficient ... definitely it's benchmark!