-
Notifications
You must be signed in to change notification settings - Fork 4
Gendarme.Rules.Maintainability.ConsiderUsingStopwatchRule(git)
Assembly: Gendarme.Rules.Maintainability
Version: git
This rule checks methods for cases where a System.Diagnostics.Stopwatch could be used instead of using System.DateTime to compute the time required for an action. Stopwatch is preferred because it better expresses the intent of the code and because (on some platforms at least) StopWatch is accurate to roughly the microsecond whereas DateTime.Now is only accurate to 16 milliseconds or so. This rule only applies to assemblies compiled with the .NET framework version 2.0 (or later).
Bad example:
public TimeSpan DoLongOperation ()
{
DateTime start = DateTime.Now;
DownloadNewOpenSuseDvdIso ();
return DateTime.Now - start;
}
Good example:
public TimeSpan DoLongOperation ()
{
Stopwatch watch = Stopwatch.StartNew ();
DownloadNewOpenSuseDvdIso ();
return watch.Elapsed;
}
- This rule is available since Gendarme 2.0
You can browse the latest source code of this rule on github.com
Note that this page was autogenerated (3/17/2011 1:55:44 PM) based on the xmldoc
comments inside the rules source code and cannot be edited from this wiki.
Please report any documentation errors, typos or suggestions to the
Gendarme Mailing List. Thanks!