下面是代码自己测试一下即可

using System.Collections;
using System.Collections.Generic;
using UnityEngine; public class TimeDuiBi : MonoBehaviour
{
List<int> list = new List<int>(); private void Start()
{
for (int i = 0; i < 3000000; i++)
{
list.Add(i);
}
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
stopwatch.Start();
int temp1 = 0;
int cout = list.Count;
for (int i = 0; i < cout; i++)
{
temp1 += list[i];
}
stopwatch.Stop();
Debug.Log("for time=: " + stopwatch.Elapsed.TotalMilliseconds + "temp1:" + temp1); System.Diagnostics.Stopwatch stopwatch2 = new System.Diagnostics.Stopwatch();
stopwatch2.Start();
int temp3 = 0;
for (int i = 0; i < list.Count; i++)
{
temp3 += list[i];
}
stopwatch2.Stop();
Debug.Log("for list.Count time=: " + stopwatch2.Elapsed.TotalMilliseconds + "temp3:" + temp3); System.Diagnostics.Stopwatch stopwatch1 = new System.Diagnostics.Stopwatch();
stopwatch1.Start();
int temp2 = 0;
foreach (var item in list)
{
temp2 += item;
}
stopwatch1.Stop();
Debug.Log("foreach time=: " + stopwatch1.Elapsed.TotalMilliseconds + "temp2:" + temp2);
}
}
}

以上就是测试的结果,不喜勿喷

搜索

复制

最新文章

  1. 在Web中实现C/S模式的Tab
  2. sql语句not in判断条件注意事项
  3. 430flash的操作
  4. ubuntu glusterfs 配置调试
  5. Modelsim的自动化脚本仿真平台
  6. 无法将类型“System.Collections.Generic.IEnumerable&lt;EmailSystem.Model.TemplateInfo&gt;”隐式转换为“System.Collections.Generic.List&lt;EmailSystem.Model.TemplateInf
  7. uva 10041 Vito&#39;s Family_贪心
  8. 基于visual Studio2013解决算法导论之019栈实现(基于数组)
  9. C#大牛应该知道的一些知识
  10. 计算机网络分层(OSI七层、 TCP/IP四层)
  11. Coursera 机器学习笔记(四)
  12. php5.6在yum下安装gd库
  13. 使用Anaconda搭建TensorFlow-GPU环境
  14. MyCat-schema.xml详解
  15. centos7配置iscsi
  16. 【NLP】Attention Model(注意力模型)学习总结
  17. 使用nexus搭建maven私服教程详解
  18. E - TOYS
  19. js如何判断访问来源是来自搜索引擎(蜘蛛人)还是直接访问
  20. Sql server 备份还原后出现“受限制用户”问题

热门文章

  1. 案例:用ajax 方法 解析xml
  2. vue 中引入iframe,动态设置其src,遇到的一些小问题总结
  3. epoll分布式通讯
  4. 【分析笔记】全志平台 gpio_wdt 驱动应用和 stack crash 解决
  5. vulnhub靶场之VENOM: 1
  6. 【转载】JAVA - 解决:Java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
  7. Idea移除和删除模块
  8. 什么是push通知栏消息?
  9. fast planner总结
  10. python3使用requests模块发https请求,提示caused by ssl error, can&#39;t connect to https url because the ssl module is not available