当前位置:网站首页>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
结果
也就是说普通方法的性能大于指定类型的泛型方法大于未指定类型的泛型方法
偶尔真的很羡慕,羡慕某些人可以过目不忘,可以举一反三,而我同一份资料往往都要看多次才能真正的看懂。
但幸运的是,很多东西真的靠努力是可以改变和得到的,多敲敲代码,自己的技术就会慢慢提高,多跑跑步,身材就会变的更好,多听听书,自己也能满腹经纶。
加油,周末,你要越来越好,这不用别人看得出来,但是自己一定要知道。
边栏推荐
- webflux - webclient Connect reset by peer Error
- 动态库基本原理和使用方法,-fPIC 选项的来龙去脉
- Coindesk comments on the decentralization process of the wave field: let people see the future of the Internet
- Robomaster visual tutorial (0) Introduction
- 手写一个模拟的ReentrantLock
- The difference between -s and -d when downloading packages using NPM
- Ping error: unknown name or service
- 搭建ADG过程中复制报错 RMAN-03009 ORA-03113
- ROS从入门到精通(九) 可视化仿真初体验之TurtleBot3
- Pigsty: out of the box database distribution
猜你喜欢
[programming problem] [scratch Level 2] 2019.09 make bat Challenge Game
DataGuard active / standby cleanup archive settings
单机高并发模型设计
Is 35 really a career crisis? No, my skills are accumulating, and the more I eat, the better
QT creator add JSON based Wizard
Coindesk comments on the decentralization process of the wave field: let people see the future of the Internet
【推荐系统基础】正负样本采样和构造
95. (cesium chapter) cesium dynamic monomer-3d building (building)
[programming questions] [scratch Level 2] March 2019 garbage classification
快速上手使用本地测试工具postman
随机推荐
从Starfish OS持续对SFO的通缩消耗,长远看SFO的价值
10 schemes to ensure interface data security
RPA云电脑,让RPA开箱即用算力无限?
[the most detailed in history] statistical description of overdue days in credit
詹姆斯·格雷克《信息简史》读后感记录
One click free translation of more than 300 pages of PDF documents
QT and OpenGL: loading 3D models using the open asset import library (assimp) - Part 2
FFA and ICGA angiography
How to measure whether the product is "just needed, high frequency, pain points"
某马旅游网站开发(对servlet的优化)
AWS AWS help error
Solution to prompt configure: error: curses library not found when configuring and installing crosstool ng tool
52歲的周鴻禕,還年輕嗎?
Daily question brushing record (16)
全自动化处理每月缺卡数据,输出缺卡人员信息
Is it safe for tongdaxin to buy funds?
【编程题】【Scratch二级】2019.03 绘制方形螺旋
Using Google test in QT
Les mots ont été écrits, la fonction est vraiment puissante!
Solutions to problems in sqlserver deleting data in tables