[C#]记录程序耗时的方法【转发】
System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();stopwatch.Start();
// Here: 需要计算耗时的过程/方法
stopwatch.Stop();
stopwatch.Elapsed.TotalSeconds //这里是输出的总运行秒数,精确到毫秒的
System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
stopwatch.Start();
byte[] a = System.IO.File.ReadAllBytes("x:\\新建文本文档.txt");
textBox2.AppendText("\r\n载入文件 总长{1} 耗时{0}秒".FormatWith(stopwatch.Elapsed.TotalSeconds, a.Length));
stopwatch.Reset(); stopwatch.Start();
byte[] b = LC.Fun.Hash.AES_Encrypt(a, "#JBP@Bb$DJGJ#1A!2");
textBox2.AppendText("\r\n加密完成 总长{1} 耗时{0}秒".FormatWith(stopwatch.Elapsed.TotalSeconds, b.Length));
stopwatch.Reset(); stopwatch.Start();
byte[] c = LC.Fun.Hash.AES_Decrypt(b, "#JBP@Bb$DJGJ#1A!2");
textBox2.AppendText("\r\n解密完成 总长{1} 耗时{0}秒".FormatWith(stopwatch.Elapsed.TotalSeconds, c.Length));
stopwatch.Stop();
学习交流群:364976091
文档来源:51CTO技术博客https://blog.51cto.com/u_176133/3335679
页:
[1]