Performance of DateTime.Parse()
I would like to write a series of posts describing the various performance issues I faced while implementing DotSVN.
In this post I discuss the performance penalty of using DateTime.Parse().
During my testing, I found that DotSVN was running quite slow. I used a trial version of 'JetBrains dotTrace 3.0' to analyze the problem. The following is a screen-shot of the dotTrace session.

As you can see, 26% of the time is spend on the method call 'System.DateTime.Parse()'. This was unacceptable. After some investigation I found that the performance of the DateTime Parse method can be improved if we give some clue on formatting of the date string. This can be achieved using the ParseExact() method.
note: I have updated the code to re-use the CultureInfo class.
AlexKucherenko - Thanks for the comment.
The performance gain is quite obvious with the following figure, which shows the dotTrace session after applying the above fix.

As you can see, DateTime.Parse() is no longer a hot Spot. This also shows the power of dotTrace, and how it helped to quickly narrow down the issue.










Comments
Hi,
try such code!!! it much faster. Do not create on each call en-US culture!!!!
private static CultureInfo s_en_us = new CultureInfo( "en-US" );
bool parseResult = DateTime.TryParseExact( dateString, dateTimeFormat,
s_en_us, DateTimeStyles.AdjustToUniversal, out parsedDate );
Posted by: AlexKucherenko | September 25, 2007 3:40 PM
Thanks for the comment. I have updated the code.
That was quite silly of me to have missed that :)
George
Posted by: George Chiramattel
|
October 1, 2007 11:28 AM