FW4与FW 3.5中DateTime.TryParseExact的性能问题 [英] Performance Issue with DateTime.TryParseExact in FW4 vs FW 3.5
本文介绍了FW4与FW 3.5中DateTime.TryParseExact的性能问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
我遇到了fw3.5和4之间的一个有趣的性能问题
I come across an interesting performance issue between fw3.5 and 4
当我在fw 4上运行此代码时,运行时间为8.39秒,但是在fw3.5上运行时,时间为0.34秒
when i run this code on fw 4 the running time is 8.39 sec but when running it on fw3.5 the time is 0.34 sec
Stopwatch stopWatch = new Stopwatch();
string formats = "%M/%d/yyyy %h:mm:%s:fff tt";
DateTime datetime = DateTime.Now;
stopWatch.Start();
for (int i = 0; i < 10000; i++)
{
DateTime dateTime;
bool isParsed = DateTime.TryParseExact(
DateTime.Now.ToString(),
formats,
new CultureInfo("en-US"),
DateTimeStyles.None,
out dateTime);
}
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
string elapsedTime = String.Format("{0:00}:{1:00}.{2:00}", ts.Minutes, ts.Seconds, ts.Milliseconds / 10);
Console.WriteLine("RunTime " + elapsedTime);
推荐答案
感兴趣...我检查了它. CultureInfo的实现方式有所不同:
Interessting... I checked it. CultureInfo is differently implemented:
1.)它在4.0中具有属性:
1.) It has a attribute in 4.0:
[SecuritySafeCritical, TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
Whatever that means..
这篇关于FW4与FW 3.5中DateTime.TryParseExact的性能问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文