当前位置:网站首页>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 .
边栏推荐
- 爬虫实战(八):爬表情包
- QT and OpenGL: load 3D models using the open asset import library (assimp)
- Reading notes 004: Wang Yangming's quotations
- [programming problem] [scratch Level 2] draw ten squares in December 2019
- [programming problem] [scratch Level 2] December 2019 flying birds
- After going to ByteDance, I learned that there are so many test engineers with an annual salary of 40W?
- fabulous! How does idea open multiple projects in a single window?
- Binder核心API
- QT creator add JSON based Wizard
- If an exception is thrown in the constructor, the best way is to prevent memory leakage?
猜你喜欢
Development of a horse tourism website (realization of login, registration and exit function)
Tencent security released the white paper on BOT Management | interpreting BOT attacks and exploring ways to protect
【编程题】【Scratch二级】2019.03 垃圾分类
Notice on organizing the second round of the Southwest Division (Sichuan) of the 2021-2022 National Youth electronic information intelligent innovation competition
Development of a horse tourism website (optimization of servlet)
QT establish signal slots between different classes and transfer parameters
华为交换机S5735S-L24T4S-QA2无法telnet远程访问
Set up personal network disk with nextcloud
每日刷题记录 (十六)
52歲的周鴻禕,還年輕嗎?
随机推荐
【史上最详细】信贷中逾期天数统计说明
哪个券商公司开户佣金低又安全,又靠谱
A brief history of information by James Gleick
How does the markdown editor of CSDN input mathematical formulas--- Latex syntax summary
Opengl3.3 mouse picking up objects
Development of a horse tourism website (optimization of servlet)
paddle一个由三个卷积层组成的网络完成cifar10数据集的图像分类任务
35岁真就成了职业危机?不,我的技术在积累,我还越吃越香了
[programming problem] [scratch Level 2] December 2019 flying birds
RPA云电脑,让RPA开箱即用算力无限?
Qt添加资源文件,为QAction添加图标,建立信号槽函数并实现
Su embedded training - Day3
Solution to the problem of unserialize3 in the advanced web area of the attack and defense world
Daily question brushing record (16)
Tencent security released the white paper on BOT Management | interpreting BOT attacks and exploring ways to protect
爬虫实战(八):爬表情包
Linkedblockingqueue source code analysis - add and delete
Common selectors are
应用实践 | 数仓体系效率全面提升!同程数科基于 Apache Doris 的数据仓库建设
C language 001: download, install, create the first C project and execute the first C language program of CodeBlocks