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]; 版权声明:本文为博主原创文章,未经博主允许不得转 ...
随机推荐
- Ionic4.x 中的 UI 组件(UI Components)表单相关组件
1.ion-input 单行文本框 2.ion-toggle 开关 3.ion-radio-group.ion-radio 单选按钮组 4.ion-checkbox 多选按钮组 5.ion-selec ...
- 简易的CRM系统案例之Servlet+Jsp+MySQL版本
数据库配置 datebase.properties driver=com.mysql.jdbc.Driver url=jdbc:mysql://127.0.0.1:3306/infos usernam ...
- 【转载】 AutoML技术现状与未来展望
原文地址: https://www.cnblogs.com/marsggbo/p/9309520.html ---------------------------------------------- ...
- 机器学习 - 算法 - SVM 支持向量机 Py 实现 / 人脸识别案例
SVM 代码实现展示 相关模块引入 %matplotlib inline import numpy as np import matplotlib.pyplot as plt from scipy i ...
- linux性能监控 -CPU、Memory、IO、Network等指标的讲解
[操作系统-linux]linux性能监控 -CPU.Memory.IO.Network等指标的讲解(转) 一.CPU 1.良好状态指标 CPU利用率:User Time <= 70%,Syst ...
- osg RTT 多相机-局部放大镜
#ifdef _WIN32 #include <Windows.h> #endif // _WIN32 #include<iostream> #include <osgV ...
- 最简易的python web框架的后端实现
1.源代码 #!/usr/bin/python #encoding=utf-8 from flask import json, Flask, request app = Flask(__name__) ...
- 阶段5 3.微服务项目【学成在线】_day16 Spring Security Oauth2_17-认证接口开发-申请令牌测试
远程 调用Spring Security来申请令牌,然后把申请到令牌存储到redis里面 cookieMaxAge: ‐1 -1表示浏览器一关闭cookie就失效. 测试远程申请令牌 TestCl ...
- jmeter 随机取一个值的方法
1.添加用户自定义变量 在要用到随机值的地方写入 ${__RandomFromMultipleVars(1|2|0)} 例子: 效果:
- SAP S/4 HANA与SAP Business Suite/R3(ECC)的区别
转自:https://blog.csdn.net/zhongguomao/article/details/53515203 去年SAP推出了新一代商务套件SAP S/4 HANA,无疑是ERP行业创新 ...