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]; 版权声明:本文为博主原创文章,未经博主允许不得转 ...
随机推荐
- <IDE>vscode前端常用插件推荐,搭建JQuery、Vue等开发环境
vscode是微软开发的的一款代码编辑器,就如官网上说的一样,vscode重新定义(redefined)了代码编辑器.当前市面上常用的轻型代码编辑器主要是:sublime,notepad++,edit ...
- 010-centos 端口问题
1.nmap 安装 yum install nmap #输入y安装 使用 nmap localhost #查看主机当前开放的端口 nmap -p 1024-65535 local ...
- linux修改配置文件解决mysql中文乱码和指定数据库存储引擎
如题,mysql数据库的中文显示乱码: 先看下原来数据库里的字符编码: mysql> show variables like '%character_set%'; +-------------- ...
- Linux -- GCC Built-in functions for atomic memory access
下列内建函数旨在兼容Intel Itanium Processor-specific Application Binary Interface, section 7.4. 因此,这些函数区别于普通的G ...
- iOS-宏定义
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAnoAAAPCCAYAAADvRHWgAAAAAXNSR0IArs4c6QAAAZ1pVFh0WE1MOm ...
- iOS-NSTimer计时器
(3) 计时器NSTimer + (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)ti target:(id)aTarget sel ...
- python 日志组件
日志组件: import logging import logging.handlers import os class logs(object): def __init__(self): self. ...
- Python----数据预处理代码实例
为方便收藏学习,转载自:https://www.jb51.net/article/158168.htm 本文实例为大家分享了Python数据预处理的具体代码,供大家参考,具体内容如下 1.导入标准库 ...
- redis的主从复制和哨兵模式
Redis主从复制是什么? 行话:也就是我们所说的主从复制,主机数据更新后根据配置和策略, 自动同步到备机的master/slaver机制,Master以写为主,Slave以读为主 Redis主从复制 ...
- [转帖]PG语法解剖--基本sql语句用法入门
PG语法解剖--基本sql语句用法入门 https://www.toutiao.com/i6710897833953722894/ COPY 命令挺好的 需要学习一下. 原创 波波说运维 2019-0 ...