当前位置:网站首页>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 .
边栏推荐
- Teach you to make a custom form label by hand
- 接口测试要测试什么?
- 每日刷题记录 (十六)
- Set up personal network disk with nextcloud
- Basic principle and usage of dynamic library, -fpic option context
- 他们齐聚 2022 ECUG Con,只为「中国技术力量」
- [programming problem] [scratch Level 2] draw ten squares in December 2019
- 【编程题】【Scratch二级】2019.12 绘制十个正方形
- 测试流程不完善,又遇到不积极的开发怎么办?
- Jouer sonar
猜你喜欢
Smart regulation enters the market, where will meituan and other Internet service platforms go
Binder核心API
Development of a horse tourism website (realization of login, registration and exit function)
某马旅游网站开发(对servlet的优化)
ROS from entry to mastery (IX) initial experience of visual simulation: turtlebot3
Daily question brushing record (16)
1293_FreeRTOS中xTaskResumeAll()接口的实现分析
某马旅游网站开发(登录注册退出功能的实现)
3年经验,面试测试岗20K都拿不到了吗?这么坑?
[programming problem] [scratch Level 2] 2019.09 make bat Challenge Game
随机推荐
Linkedblockingqueue source code analysis - add and delete
Go learning notes (2) basic types and statements (1)
QT creator add JSON based Wizard
What if the testing process is not perfect and the development is not active?
CoinDesk评波场去中心化进程:让人们看到互联网的未来
52歲的周鴻禕,還年輕嗎?
52岁的周鸿祎,还年轻吗?
Stm32f1 and stm32cubeide programming example - rotary encoder drive
大数据开源项目,一站式全自动化全生命周期运维管家ChengYing(承影)走向何方?
搭建ADG过程中复制报错 RMAN-03009 ORA-03113
关于组织2021-2022全国青少年电子信息智能创新大赛西南赛区(四川)复赛的通知
Robomaster visual tutorial (0) Introduction
Binder核心API
【编程题】【Scratch二级】2019.09 绘制雪花图案
[programming problem] [scratch Level 2] March 2019 draw a square spiral
数据库查询——第几高的数据?
35岁真就成了职业危机?不,我的技术在积累,我还越吃越香了
If an exception is thrown in the constructor, the best way is to prevent memory leakage?
Introduction knowledge system of Web front-end engineers
【编程题】【Scratch二级】2019.09 制作蝙蝠冲关游戏