当前位置: 首页 > news >正文

黑龙江住房和城乡建设局网站焦作seo公司

黑龙江住房和城乡建设局网站,焦作seo公司,网站正在建设中 源码下载,花生壳可做网站吗首先#xff0c;非常感谢赵老大的CodeTimer#xff0c;它让我们更好的了解到代码执行的性能#xff0c;从而可以让我们从性能的角度来考虑问题#xff0c;有些东西可能我们认为是这样的#xff0c;但经理测试并非如何#xff0c;这正应了我之前的那名话#xff1a;“机器…首先非常感谢赵老大的CodeTimer它让我们更好的了解到代码执行的性能从而可以让我们从性能的角度来考虑问题有些东西可能我们认为是这样的但经理测试并非如何这正应了我之前的那名话“机器最能证明一切” 费话就不说了看代码吧 1 /// summary2 /// 执行代码规范3 /// /summary4 public interface IAction5 {6 void Action();7 }8 9 /// summary10 /// 老赵的性能测试工具11 /// /summary12 public static class CodeTimer13 {14 [DllImport(kernel32.dll, SetLastError true)]15 static extern bool GetThreadTimes(IntPtr hThread, out long lpCreationTime, out long lpExitTime, out long lpKernelTime, out long lpUserTime);16 17 [DllImport(kernel32.dll)]18 static extern IntPtr GetCurrentThread();19 public delegate void ActionDelegate();20 private static long GetCurrentThreadTimes()21 {22 long l;23 long kernelTime, userTimer;24 GetThreadTimes(GetCurrentThread(), out l, out l, out kernelTime, out userTimer);25 return kernelTime userTimer;26 }27 static CodeTimer()28 {29 Process.GetCurrentProcess().PriorityClass ProcessPriorityClass.High;30 Thread.CurrentThread.Priority ThreadPriority.Highest;31 }32 public static void Time(string name, int iteration, ActionDelegate action)33 {34 if (String.IsNullOrEmpty(name))35 {36 return;37 }38 if (action null)39 {40 return;41 }42 43 //1. Print name44 ConsoleColor currentForeColor Console.ForegroundColor;45 Console.ForegroundColor ConsoleColor.Yellow;46 Console.WriteLine(name);47 48 // 2. Record the latest GC counts49 //GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);50 GC.Collect(GC.MaxGeneration);51 int[] gcCounts new int[GC.MaxGeneration 1];52 for (int i 0; i GC.MaxGeneration; i)53 {54 gcCounts[i] GC.CollectionCount(i);55 }56 57 // 3. Run action58 Stopwatch watch new Stopwatch();59 watch.Start();60 long ticksFst GetCurrentThreadTimes(); //100 nanosecond one tick61 for (int i 0; i iteration; i) action();62 long ticks GetCurrentThreadTimes() - ticksFst;63 watch.Stop();64 65 // 4. Print CPU66 Console.ForegroundColor currentForeColor;67 Console.WriteLine(\tTime Elapsed:\t\t 68 watch.ElapsedMilliseconds.ToString(N0) ms);69 Console.WriteLine(\tTime Elapsed (one time): 70 (watch.ElapsedMilliseconds / iteration).ToString(N0) ms);71 Console.WriteLine(\tCPU time:\t\t (ticks * 100).ToString(N0)72 ns);73 Console.WriteLine(\tCPU time (one time):\t (ticks * 100 /74 iteration).ToString(N0) ns);75 76 // 5. Print GC77 for (int i 0; i GC.MaxGeneration; i)78 {79 int count GC.CollectionCount(i) - gcCounts[i];80 Console.WriteLine(\tGen i : \t\t\t count);81 }82 Console.WriteLine();83 }84 85 86 87 public static void Time(string name, int iteration, IAction action)88 {89 if (String.IsNullOrEmpty(name))90 {91 return;92 }93 94 if (action null)95 {96 return;97 }98 99 //1. Print name 100 ConsoleColor currentForeColor Console.ForegroundColor; 101 Console.ForegroundColor ConsoleColor.Yellow; 102 Console.WriteLine(name); 103 104 // 2. Record the latest GC counts 105 //GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced); 106 GC.Collect(GC.MaxGeneration); 107 int[] gcCounts new int[GC.MaxGeneration 1]; 108 for (int i 0; i GC.MaxGeneration; i) 109 { 110 gcCounts[i] GC.CollectionCount(i); 111 } 112 113 // 3. Run action 114 Stopwatch watch new Stopwatch(); 115 watch.Start(); 116 long ticksFst GetCurrentThreadTimes(); //100 nanosecond one tick 117 for (int i 0; i iteration; i) action.Action(); 118 long ticks GetCurrentThreadTimes() - ticksFst; 119 watch.Stop(); 120 121 // 4. Print CPU 122 Console.ForegroundColor currentForeColor; 123 Console.WriteLine(\tTime Elapsed:\t\t 124 watch.ElapsedMilliseconds.ToString(N0) ms); 125 Console.WriteLine(\tTime Elapsed (one time): 126 (watch.ElapsedMilliseconds / iteration).ToString(N0) ms); 127 Console.WriteLine(\tCPU time:\t\t (ticks * 100).ToString(N0) 128 ns); 129 Console.WriteLine(\tCPU time (one time):\t (ticks * 100 / 130 iteration).ToString(N0) ns); 131 132 // 5. Print GC 133 for (int i 0; i GC.MaxGeneration; i) 134 { 135 int count GC.CollectionCount(i) - gcCounts[i]; 136 Console.WriteLine(\tGen i : \t\t\t count); 137 } 138 Console.WriteLine(); 139 } 140 } 有了上面的codeTimer我们就来测试一个吧如字条串和并的问题用还是用StringBuilder呢有点经验的程序员肯定说是StringBuilder是的确实是后者那我们就来看看这 两种方法测试的结果吧 1 CodeTimer.Time(String Concat, 100000,2 () 3 {4 var s 1;5 for (int i 1; i 10; i)6 s s 1;7 });8 9 CodeTimer.Time(StringBuilder Concat, 100000, 10 () 11 { 12 var s new StringBuilder(); 13 for (int i 1; i 10; i) 14 s.Append(1); 15 }); 测试的结果如下 从图中我们可以看到StringBuilder快的很明显无论是执行时间还是对CPU的消耗及GC回收都远低于String的拼结所以才有以下结论 在字符串拼结时请使用StringBuilder吧转载于:https://www.cnblogs.com/jjg0519/p/8309590.html
http://www.zqtcl.cn/news/820164/

相关文章:

  • 联邦快递的网站建设图书馆建设网站注意点
  • 西安好的皮肤管理做团购网站wordpress stats
  • 文山 网站建设 滇icp卡盟网站顶图怎么做
  • 北京网站建设公司哪些好电商建站
  • 沈阳百度广告广州营销seo
  • 营销型企业网站建设步骤做网站怎样和客户沟通
  • 多媒体教学网站开发的一般步骤网络公司网站赏析
  • 阿里云手机网站建设多少钱wordpress幻灯片制作
  • 个人博客网站下载公司邮箱免费注册
  • 厦门外贸网站建设多少钱wordpress 增大字体
  • 可以做外链的网站有哪些外贸阿里巴巴国际站
  • 潮安区住房和城乡建设局网站网站开发技术分析
  • 网站跳出率因素建设单位应该关注的网站
  • php开发的大型金融网站有哪些网站开发可以自学吗
  • 个人建网站成本wordpress 增加阅读量
  • wordpress构建自己的网站大连网站建设主页
  • 棋牌网站开发工程师网站app制作费用单
  • 为什么做网站比app便宜精准营销服务
  • 网站平台做捐助功能有风险吗wordpress博客 翻墙
  • 泰州网站建设专业团队长沙seo顾问
  • 网站建设情况简介seo的基本步骤顺序正确的是
  • wordpress 文件目录结构关键字优化价格
  • 连云港网站关键字优化市场网站 设计 文档
  • 哈尔滨企业建站服务商龙岩建筑网
  • 四川住房城乡建设厅官方网站中国建设银行在网站怎么签约
  • wordpress tortuga安徽seo网站
  • 厦门商务网站建设网络规划与设计实用教程
  • win8风格门户网站已经建网站做外贸
  • 自己有域名如何做网站wordpress文章中外链
  • 网站模糊背景加快网站速度吗