当前位置:网站首页>C# 泛型及性能比较
C# 泛型及性能比较
2022-07-07 22:17:00 【太阳的后裔】
什么是泛型?通俗的说就是不确定的类型。
什么时候用到泛型?当我们想要使用一个方法接收多种不同的类型的参数的时候我们常常能够用到。
public static void Show()
{
Console.WriteLine("****************Monitor******************");
{
int iValue = 12345;
long commonSecond = 0;
long objectSecond = 0;
long genericSecond = 0;
{
Stopwatch watch = new Stopwatch();
watch.Start();
for (int i = 0; i < 100_000_000; i++)
{
ShowInt(iValue);
}
watch.Stop();
commonSecond = watch.ElapsedMilliseconds;
}
{
Stopwatch watch = new Stopwatch();
watch.Start();
for (int i = 0; i < 100_000_000; i++)
{
ShowObject(iValue);
}
watch.Stop();
objectSecond = watch.ElapsedMilliseconds;
}
{
Stopwatch watch = new Stopwatch();
watch.Start();
for (int i = 0; i < 100_000_000; i++)
{
Show<int>(iValue);
}
watch.Stop();
genericSecond = watch.ElapsedMilliseconds;
}
Console.WriteLine("commonSecond={0},objectSecond={1},genericSecond={2}"
, commonSecond, objectSecond, genericSecond);
}
}
#region PrivateMethod
private static void ShowInt(int iParameter)
{
//do nothing
}
private static void ShowObject(object oParameter)
{
//do nothing
}
private static void Show<T>(T tParameter)
{
//do nothing
}
#endregion
结果
也就是说普通方法的性能大于指定类型的泛型方法大于未指定类型的泛型方法
偶尔真的很羡慕,羡慕某些人可以过目不忘,可以举一反三,而我同一份资料往往都要看多次才能真正的看懂。
但幸运的是,很多东西真的靠努力是可以改变和得到的,多敲敲代码,自己的技术就会慢慢提高,多跑跑步,身材就会变的更好,多听听书,自己也能满腹经纶。
加油,周末,你要越来越好,这不用别人看得出来,但是自己一定要知道。
边栏推荐
- Smart regulation enters the market, where will meituan and other Internet service platforms go
- Linkedblockingqueue source code analysis - add and delete
- Basic learning of SQL Server -- creating databases and tables with code
- 【编程题】【Scratch二级】2019.09 绘制雪花图案
- 80%的人答错,苹果logo上的叶子到底朝左还是朝右?
- Pigsty: out of the box database distribution
- 詹姆斯·格雷克《信息简史》读后感记录
- Traduction gratuite en un clic de plus de 300 pages de documents PDF
- 2022-07-07:原本数组中都是大于0、小于等于k的数字,是一个单调不减的数组, 其中可能有相等的数字,总体趋势是递增的。 但是其中有些位置的数被替换成了0,我们需要求出所有的把0替换的方案数量:
- 用语雀写文章了,功能真心强大!
猜你喜欢

Set up personal network disk with nextcloud

Problems faced when connecting to sqlserver after downloading (I)

How does starfish OS enable the value of SFO in the fourth phase of SFO destruction?
![[path planning] use the vertical distance limit method and Bessel to optimize the path of a star](/img/0b/e21f7ded7c854272e8cb631ff0154e.png)
[path planning] use the vertical distance limit method and Bessel to optimize the path of a star

10 schemes to ensure interface data security

The underlying principles and templates of new and delete

搭建ADG过程中复制报错 RMAN-03009 ORA-03113

一鍵免費翻譯300多頁的pdf文檔

DataGuard active / standby cleanup archive settings

从Starfish OS持续对SFO的通缩消耗,长远看SFO的价值
随机推荐
2022-07-07:原本数组中都是大于0、小于等于k的数字,是一个单调不减的数组, 其中可能有相等的数字,总体趋势是递增的。 但是其中有些位置的数被替换成了0,我们需要求出所有的把0替换的方案数量:
面试题详解:用Redis实现分布式锁的血泪史
Pigsty: out of the box database distribution
【转载】解决conda安装pytorch过慢的问题
Basic learning of SQL Server -- creating databases and tables with code
95. (cesium chapter) cesium dynamic monomer-3d building (building)
AWS AWS help error
Reading notes 004: Wang Yangming's quotations
某马旅游网站开发(对servlet的优化)
10 schemes to ensure interface data security
[the most detailed in history] statistical description of overdue days in credit
Two small problems in creating user registration interface
Database interview questions + analysis
每日刷题记录 (十六)
【史上最详细】信贷中逾期天数统计说明
Solution to prompt configure: error: curses library not found when configuring and installing crosstool ng tool
One click free translation of more than 300 pages of PDF documents
如何衡量产品是否“刚需、高频、痛点”
One click installation with fishros in blue bridge ROS
How to measure whether the product is "just needed, high frequency, pain points"