- document.write()使用简介
- JavaScript程序构成
- 怎么样用vs2008打开用vs2010编的文件
- window系统密码忘记技巧大搜罗
- IIS服务器、Apache服务器、ASP、.Net、PHP实现301重定向的方法
- 其他网站定制
- c#中用sql语句创建表中默认值与sql server之不同
- CSS中的“>”符号作用
- 盲盒交友项目解析
- 如何把握关键词的竞争力度
邮箱:
手机:15383239821
List中contains方法和indexOf方法的区别
contain是判断List是否包含某个对象成员,返回布尔类型。
IndexOf是判断对象在该list里面的位置,没有返回-1,有的话返回索引位置。
在list中,存在三种方法:contains, exists, any。都可以实现查找元素。下面来做个测试,看下他们之间的性能比较如何。
测试代码如下:
List list = new List();
int n=1000000;
for (int i = 0; i < n; i++)
{
list.add(i);
}
system.diagnostics.stopwatch sw = new system.diagnostics.stopwatch();
sw.start();
//console.writeline(list.contains(n));
// console.writeline(list.any(i => i == n));
//console.writeline(list.exists(i => i == n));
sw.stop();
console.writeline(sw.elapsed.tostring());
n=1000000 n=10000000 n=100000000
contains 0.0042733(s) 0.0294047(s) 0.3624644(s)
exists 0.0059634(s) 0.0420811(s) 0.4055032(s)
any 0.0128684(s) 0.1084404(s) 1.1051506(s)
根据上表结果显示,性能从高到低的次序如下:
contains>exists>any
-
2013-10-30ASP.NET在IIS7.5(IIS7)配置伪静态
-
2012-06-30浅谈修改网站标题利与弊
-
2019-11-25dtcms建站流程
-
2023-09-09详细VScode安装教程
-
2023-02-24在VScode中开启自动换行
-
2010-11-11浅谈关键词优化的七个方面
