博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HashSet 、 Dictionary 、List性能对比
阅读量:2288 次
发布时间:2019-05-09

本文共 1507 字,大约阅读时间需要 5 分钟。

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Diagnostics;namespace UrlMatchSiteNameModule{    class Program    {        static void Main(string[] args)        {            const int COUNT = 1000000;            HashSet
hashSetOfInts = new HashSet
(); Stopwatch stopWatch = new Stopwatch(); for (int i = 0; i < COUNT; i++) { hashSetOfInts.Add(i); } stopWatch.Start(); for (int i = 0; i < COUNT; i++) { hashSetOfInts.Contains(i); } stopWatch.Stop(); Console.WriteLine(stopWatch.Elapsed); stopWatch.Reset(); Dictionary
domainMap = new Dictionary
(); for (int i = 0; i < COUNT; i++) { domainMap.Add(i.ToString(), i.ToString()); } stopWatch.Start(); string value; for (int i = 0; i < COUNT; i++) { domainMap.TryGetValue(i.ToString(), out value); } stopWatch.Stop(); Console.WriteLine(stopWatch.Elapsed); stopWatch.Reset(); List
listOfInts = new List
(); for (int i = 0; i < COUNT; i++) { listOfInts.Add(i); } stopWatch.Start(); for (int i = 0; i < COUNT; i++) { listOfInts.Contains(i); } stopWatch.Stop(); Console.WriteLine(stopWatch.Elapsed); Console.Read(); } }}

转载地址:http://rrunb.baihongyu.com/

你可能感兴趣的文章
Linux 快捷键
查看>>
JPA 联合主键配置
查看>>
ObjectAlreadyExistsException:Unable to store Job : '*', because one already exists with thi s ident
查看>>
mybatis & JPA 实体类型属性转换
查看>>
Git 中的 ~ 和 ^
查看>>
第一篇博客,给大家分享java、架构师、大数据、人工智能的学习路线,希望能够帮助到大家
查看>>
18级大数据专家,跟大家漫谈大数据平台架构,你能学到多少?上篇
查看>>
18级大数据专家,漫谈大数据平台安全风险与建设,值得学(下篇)
查看>>
阿里P8终于整理出:Nginx+jvm+MySQL+Docker+Spring实战技术文档
查看>>
腾讯T4专家精心整理:大数据+机器学习+数据挖掘+算法大集结
查看>>
阿里P8终于总结出:SpringBoot+Tomcat+Nginx+Netty面试题及答案
查看>>
阿里P7大牛,深入剖析JVM底层设计原理+高级特性pdf,附46页ppt
查看>>
史上最全141道大数据面试题:Redis+Linux+kafka+Hadoop,附答案
查看>>
一文带你深入理解JVM,看完之后你还敢说你懂JVM吗?颠覆you认知
查看>>
这些大厂面试真题你能答出来,年薪至少30-50W,想不想挑战一下?
查看>>
携程T7用637页PDF,解读十余热门技术领域,八场携程技术沙龙干货
查看>>
开发框架SpringBoot:构建SpringBoot工程+配置文件详解+Actuator
查看>>
6年拉力工作经验,学了阿里P8级架构师的7+1+1落地项目,跳槽阿里年薪直接40W+
查看>>
90天吃透阿里P8推荐的625页Java编程兵书技术实战,直接入职阿里定级P6
查看>>
清华毕业扫地僧,用157集终于把java给讲完了,总计3.13GB
查看>>