« Announcing DotSVN.Net site | Main | Tools used for DotSVN - Resharper »

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.
DateTime.Parse() Performance issue

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.
DateTime.ParseExact() solution

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.

TrackBack

Listed below are links to weblogs that reference Performance of DateTime.Parse():

» Tools used for DotSVN - Resharper from Revelations
I have been using a trial version of ReSharper for my DotSVN project and I should say that I just got hooked to it. I would not have made this much progress without it and that leaves me wondering what I would do once the trial expires!! A tool with th... [Read More]

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 );

Thanks for the comment. I have updated the code.

That was quite silly of me to have missed that :)
George

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

Archives

Subscribe by e-mail

Creative Commons License
This weblog is licensed under a Creative Commons License.