当前位置:网站首页>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 .
边栏推荐
- 华泰证券官方网站开户安全吗?
- STM32F1与STM32CubeIDE编程实例-旋转编码器驱动
- Reading notes 004: Wang Yangming's quotations
- 测试流程不完善,又遇到不积极的开发怎么办?
- Usage of limit and offset (Reprint)
- paddle入门-使用LeNet在MNIST实现图像分类方法二
- 深潜Kotlin协程(二十三 完结篇):SharedFlow 和 StateFlow
- Vscode software
- Reptile practice (VIII): reptile expression pack
- paddle入门-使用LeNet在MNIST实现图像分类方法一
猜你喜欢
![[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.12 绘制十个正方形
![[programming problem] [scratch Level 2] March 2019 draw a square spiral](/img/fa/ae9dabdd36ba77b1f4644dd23bee93.png)
[programming problem] [scratch Level 2] March 2019 draw a square spiral

redis你到底懂不懂之list

Installation and configuration of sublime Text3

Anaconda+pycharm+pyqt5 configuration problem: pyuic5 cannot be found exe

STM32F1與STM32CubeIDE編程實例-旋轉編碼器驅動

他们齐聚 2022 ECUG Con,只为「中国技术力量」

Play sonar

【史上最详细】信贷中逾期天数统计说明
随机推荐
Sqlite数据库存储目录结构邻接表的实现2-目录树的构建
[programming problem] [scratch Level 2] December 2019 flying birds
某马旅游网站开发(对servlet的优化)
攻防世界Web进阶区unserialize3题解
Leetcode brush questions
Linkedblockingqueue source code analysis - add and delete
STM32F1與STM32CubeIDE編程實例-旋轉編碼器驅動
【编程题】【Scratch二级】2019.03 绘制方形螺旋
LeetCode刷题
接口测试要测试什么?
Fully automated processing of monthly card shortage data and output of card shortage personnel information
华泰证券官方网站开户安全吗?
Smart regulation enters the market, where will meituan and other Internet service platforms go
RPA云电脑,让RPA开箱即用算力无限?
51与蓝牙模块通讯,51驱动蓝牙APP点灯
Use filters to count URL request time
Vscode software
Reptile practice (VIII): reptile expression pack
The standby database has been delayed. Check that the MRP is wait_ for_ Log, apply after restarting MRP_ Log but wait again later_ for_ log
【编程题】【Scratch二级】2019.03 垃圾分类