当前位置:网站首页>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 .
边栏推荐
- The difference between get and post
- 【编程题】【Scratch二级】2019.03 绘制方形螺旋
- 【obs】Impossible to find entrance point CreateDirect3D11DeviceFromDXGIDevice
- QT adds resource files, adds icons for qaction, establishes signal slot functions, and implements
- STM32F1与STM32CubeIDE编程实例-旋转编码器驱动
- 接口测试要测试什么?
- 某马旅游网站开发(对servlet的优化)
- Qt添加资源文件,为QAction添加图标,建立信号槽函数并实现
- Sqlite数据库存储目录结构邻接表的实现2-目录树的构建
- Summary of the third course of weidongshan
猜你喜欢

51与蓝牙模块通讯,51驱动蓝牙APP点灯

QT and OpenGL: load 3D models using the open asset import library (assimp)
![[question de programmation] [scratch niveau 2] oiseaux volants en décembre 2019](/img/5e/a105f8615f3991635c9ffd3a8e5836.png)
[question de programmation] [scratch niveau 2] oiseaux volants en décembre 2019

【编程题】【Scratch二级】2019.09 绘制雪花图案

80%的人答错,苹果logo上的叶子到底朝左还是朝右?

Qt添加资源文件,为QAction添加图标,建立信号槽函数并实现

Smart regulation enters the market, where will meituan and other Internet service platforms go

Development of a horse tourism website (realization of login, registration and exit function)

52歲的周鴻禕,還年輕嗎?
![[研发人员必备]paddle 如何制作自己的数据集,并显示。](/img/50/3d826186b563069fd8d433e8feefc4.png)
[研发人员必备]paddle 如何制作自己的数据集,并显示。
随机推荐
Using Google test in QT
RPA cloud computer, let RPA out of the box with unlimited computing power?
ReentrantLock 公平锁源码 第0篇
Leetcode brush questions
【obs】Impossible to find entrance point CreateDirect3D11DeviceFromDXGIDevice
Cause analysis and solution of too laggy page of [test interview questions]
Use filters to count URL request time
Go learning notes (2) basic types and statements (1)
数据库查询——第几高的数据?
从Starfish OS持续对SFO的通缩消耗,长远看SFO的价值
Reading notes 004: Wang Yangming's quotations
哪个券商公司开户佣金低又安全,又靠谱
Summary of weidongshan phase II course content
2022-07-07:原本数组中都是大于0、小于等于k的数字,是一个单调不减的数组, 其中可能有相等的数字,总体趋势是递增的。 但是其中有些位置的数被替换成了0,我们需要求出所有的把0替换的方案数量:
Relevant methods of sorting arrays in JS (if you want to understand arrays, it's enough to read this article)
[programming problem] [scratch Level 2] 2019.09 make bat Challenge Game
Stm32f1 and stm32cubeide programming example - rotary encoder drive
QT and OpenGL: loading 3D models using the open asset import library (assimp) - Part 2
Sqlite数据库存储目录结构邻接表的实现2-目录树的构建
new和delete的底层原理以及模板