C# 循环中 直接索引 VS 缓存索引 性能测试
using System; namespace TestCSharp
{
class MainClass
{
public class t1 {
public b1 b = new b1();
} public class b1 {
public t2 t = new t2();
} public class t2 {
public b2 b = new b2();
} public class b2 {
public t3 t = new t3();
} public class t3 {
public b3 b = new b3();
} public class b3 {
public t4 t = new t4();
} public class t4 {
public b4 b = new b4();
} public class b4 {
public t5 t = new t5();
} public class t5 {
public b5 b = new b5();
} public class b5 {
public t6 t = new t6();
} public class t6 {
public b6 b = new b6();
} public class b6 {
public int x = ;
} public static int stimes = ; public static void Main (string[] args)
{
int times = stimes;
t1 test1 = new t1();
DateTime s1 = DateTime.Now;
for (int i = ; i < times; i++)
{
test1.b.t.b.t.b.t.b.t.b.t.b.x ++;
}
DateTime e1 = DateTime.Now;
Console.WriteLine("time1 = " + (e1 - s1).Milliseconds); t1 test2 = new t1();
DateTime s2 = DateTime.Now;
b6 b2 = test2.b.t.b.t.b.t.b.t.b.t.b;
for (int i = ; i < times; i++)
{
b2.x ++;
}
DateTime e2 = DateTime.Now;
Console.WriteLine("time2 = " + (e2 - s2).Milliseconds); t1 test3 = new t1();
DateTime s3 = DateTime.Now;
b6 b3 = test3.b.t.b.t.b.t.b.t.b.t.b;
for (int i = ; i < times; i++)
{
b3.x = b3.x + ;
}
DateTime e3 = DateTime.Now;
Console.WriteLine("time3 = " + (e3 - s3).Milliseconds); t1 test4 = new t1();
DateTime s4 = DateTime.Now;
b6 b4 = test4.b.t.b.t.b.t.b.t.b.t.b;
for (int i = ; i < stimes; i++)
{
b4.x = b4.x + ;
}
DateTime e4 = DateTime.Now;
Console.WriteLine("time4 = " + (e4 - s4).Milliseconds); t1 test5 = new t1();
DateTime s5 = DateTime.Now;
b6 b5 = test5.b.t.b.t.b.t.b.t.b.t.b;
for (int i = ; i < ; i++)
{
b5.x = b5.x + ;
}
DateTime e5 = DateTime.Now;
Console.WriteLine("time5 = " + (e5 - s5).Milliseconds);
} }
}
output:
time1 = 456
time2 = 144
time3 = 145
time4 = 145
time5 = 179
请按任意键继续. . .
总结: 缓存一下总是有好处的
C# 循环中 直接索引 VS 缓存索引 性能测试的更多相关文章
- Lua table直接索引VS缓存索引性能测试小示例
local p = {} p.t = {} p.t.p = {} p.t.p.t = {} p.t.p.t.p = {} p.t.p.t.p.t = {} p.t.p.t.p.t.p = {} p.t ...
- js模版引擎handlebars.js实用教程——循环中使用索引
<!DOCTYPE html> <html> <head> <META http-equiv=Content-Type content="text/ ...
- Handlebars.js循环中索引(@index)使用技巧(访问父级索引)
使用Handlebars.js过程中,难免会使用循环,比如构造数据表格.而使用循环,又经常会用到索引,也就是获取当前循环到第几次了,一般会以这个为序号显示在页面上. Handlebars.js中获取循 ...
- 使用jQuery+huandlebars循环中索引(@index)使用技巧(访问父级索引)
兼容ie8(很实用,复制过来,仅供技术参考,更详细内容请看源地址:http://www.cnblogs.com/iyangyuan/archive/2013/12/12/3471227.html) & ...
- Ajax请求php返回json对象数据中包含有数字索引和字符串索引,在for in循环中取出数据的顺序问题
//php中的数组数据格式 Array ( [all] => Array ( [title] => ALL [room_promotion_id] => all ) [best_av ...
- MySQL 中Index Condition Pushdown (ICP 索引条件下推)和Multi-Range Read(MRR 索引多范围查找)查询优化
一.ICP优化原理 Index Condition Pushdown (ICP),也称为索引条件下推,体现在执行计划的上是会出现Using index condition(Extra列,当然Extra ...
- WebGIS中一种根据网格索引判断点面关系的方法
文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/. 1.背景 判断点面关系的算法有很多,在我之前的博文中有一篇专门对其进行 ...
- SQL SERVER中关于OR会导致索引扫描或全表扫描的浅析
在SQL SERVER的查询语句中使用OR是否会导致不走索引查找(Index Seek)或索引失效(堆表走全表扫描 (Table Scan).聚集索引表走聚集索引扫描(Clustered Index ...
- IOS中 什么是UITableView的索引放大镜字符
IOS中 什么是UITableView的索引放大镜字符 [_dataSource addObject:UITableViewIndexSearch]; 版权声明:本文为博主原创文章,未经博主允许不得转 ...
随机推荐
- C# 多线程Thread.IsBackground=True的作用
C#中多线程的线程加.IsBackground = true与不加有什么区别? 按照MSDN上讲:“获取或设置一个值,该值指示某个线程是否为后台线程.” 其实这个解释并不到位,至少应该解释一下后台线程 ...
- 解决Vue编译和打包时频繁内存溢出情况CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
解决Vue编译和打包时频繁内存溢出情况CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory 如上图所示:频繁出现此 ...
- angular绑定数据
Angular 中使用{{}}绑定业务逻辑里面定义的数据 <h1> Welcome to {{ title }}! /*引入title*/ </h1> export class ...
- Docker,就放弃了把日志写入文件
日志配置 既然用 Docker,就放弃了把日志写入文件,直接写到标准输出. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 ...
- The pom for XXX is missing,no dependency information available
笔者进行性能测试时,碰到如下问题 性能测试代码编写,调试通过之后.使用cmd进入项目根目录,意图打包导出项目中所有的依赖包,以便导入至jmeter工具中 cmd中使用命令:mvn dependency ...
- ireport如何拼接sql?
ireport如何拼接sql ireport如何拼接sql? 解决方法: 1.ireport的sql select * from emp as e $P!{whereSQL}; 2.java代码 ...
- MySQL 5.6 my.cnf优化后的标准配置(4核 16G Centos6.5 x64)
[client] port = 3306 socket = /var/lib/mysql/mysql.sock [mysql] #这个配置段设置启动MySQL服务的条件:在这种情况下,no-auto- ...
- 按css查询多个元素
示例2 查询多个元素 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 <!DOC ...
- eclipse界面
Eclipse工作空间的基本配置 A:行号的显示和隐藏 显示:在代码区域的最左边的空白区域,右键 -- Show Line Numbers即可. 隐藏:把上面的动作再做一次. B:字体大小及颜色 a: ...
- 判断scrollView的滑动方向(二)
在上一篇文章<判断scrollView的滑动方向>中谈到的第二种方法是根据滑动速率来判断的. 今天将通过滑动过程中的坐标差来判断 - (void)scrollViewDidScroll:( ...