当前位置:网站首页>C # generics and performance comparison
C # generics and performance comparison
2022-07-08 00:22:00 【A descendant of the sun】
What is generics ? Generally speaking, it is the type of uncertainty .
When to use generics ? When we want to use a method to receive many different types of parameters, we can often use .
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
result
In other words, the performance of ordinary methods is greater than that of generic methods of specified types, and greater than that of generic methods of unspecified types
Sometimes I really envy , Envy some people can never forget , We can draw inferences from one example , And I often have to read the same information many times to really understand .
But fortunately , Many things can be changed and obtained by hard work , Knock more code , Your skills will gradually improve , Run more , Your figure will get better , Listen to books more , I can also be full of experience .
come on. , Over the weekend , You should be better and better , This need not be seen by others , But you must know .
边栏推荐
- 35岁真就成了职业危机?不,我的技术在积累,我还越吃越香了
- 某马旅游网站开发(对servlet的优化)
- Anaconda+pycharm+pyqt5 configuration problem: pyuic5 cannot be found exe
- Database query - what is the highest data?
- redis你到底懂不懂之list
- Coindesk comments on the decentralization process of the wave field: let people see the future of the Internet
- Flask learning record 000: error summary
- 52岁的周鸿祎,还年轻吗?
- RPA cloud computer, let RPA out of the box with unlimited computing power?
- 22年秋招心得
猜你喜欢
ReentrantLock 公平锁源码 第0篇
腾讯安全发布《BOT管理白皮书》|解读BOT攻击,探索防护之道
redis你到底懂不懂之list
CoinDesk评波场去中心化进程:让人们看到互联网的未来
1293_FreeRTOS中xTaskResumeAll()接口的实现分析
Notice on organizing the second round of the Southwest Division (Sichuan) of the 2021-2022 National Youth electronic information intelligent innovation competition
The underlying principles and templates of new and delete
[the most detailed in history] statistical description of overdue days in credit
【史上最详细】信贷中逾期天数统计说明
Is Zhou Hongyi, 52, still young?
随机推荐
Installation and configuration of sublime Text3
CoinDesk评波场去中心化进程:让人们看到互联网的未来
35岁真就成了职业危机?不,我的技术在积累,我还越吃越香了
QT and OpenGL: loading 3D models using the open asset import library (assimp) - Part 2
玩转Sonar
Reptile practice (VIII): reptile expression pack
赞!idea 如何单窗口打开多个项目?
[programming problem] [scratch Level 2] draw ten squares in December 2019
Experience of autumn recruitment in 22 years
哪个券商公司开户佣金低又安全,又靠谱
ReentrantLock 公平锁源码 第0篇
Flask learning record 000: error summary
Robomaster visual tutorial (0) Introduction
C# 泛型及性能比较
3年经验,面试测试岗20K都拿不到了吗?这么坑?
Single machine high concurrency model design
What if the testing process is not perfect and the development is not active?
快速上手使用本地测试工具postman
【编程题】【Scratch二级】2019.03 绘制方形螺旋
【编程题】【Scratch二级】2019.12 绘制十个正方形