当前位置:网站首页>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 .
边栏推荐
- How can CSDN indent the first line of a paragraph by 2 characters?
- [basis of recommendation system] sampling and construction of positive and negative samples
- Flask learning record 000: error summary
- Trust orbtk development issues 2022
- Vscode software
- How to put recyclerview in nestedscrollview- How to put RecyclerView inside NestedScrollView?
- 【编程题】【Scratch二级】2019.09 绘制雪花图案
- Experience of autumn recruitment in 22 years
- 3 years of experience, can't you get 20K for the interview and test post? Such a hole?
- Is 35 really a career crisis? No, my skills are accumulating, and the more I eat, the better
猜你喜欢
RPA云电脑,让RPA开箱即用算力无限?
关于组织2021-2022全国青少年电子信息智能创新大赛西南赛区(四川)复赛的通知
Zhou Hongqi, 52 ans, est - il encore jeune?
[programming problem] [scratch Level 2] 2019.09 make bat Challenge Game
Coindesk comments on the decentralization process of the wave field: let people see the future of the Internet
Fully automated processing of monthly card shortage data and output of card shortage personnel information
5G NR 系统消息
[programming problem] [scratch Level 2] December 2019 flying birds
Go learning notes (2) basic types and statements (1)
2022-07-07:原本数组中都是大于0、小于等于k的数字,是一个单调不减的数组, 其中可能有相等的数字,总体趋势是递增的。 但是其中有些位置的数被替换成了0,我们需要求出所有的把0替换的方案数量:
随机推荐
攻防世界Web进阶区unserialize3题解
他们齐聚 2022 ECUG Con,只为「中国技术力量」
接口测试要测试什么?
If an exception is thrown in the constructor, the best way is to prevent memory leakage?
A brief history of information by James Gleick
Open display PDF file in web page
Set up personal network disk with nextcloud
C language 005: common examples
备库一直有延迟,查看mrp为wait_for_log,重启mrp后为apply_log但过一会又wait_for_log
80% of the people answered incorrectly. Does the leaf on the apple logo face left or right?
How can CSDN indent the first line of a paragraph by 2 characters?
哪个券商公司开户佣金低又安全,又靠谱
每日刷题记录 (十六)
【转载】解决conda安装pytorch过慢的问题
Usage of limit and offset (Reprint)
[basis of recommendation system] sampling and construction of positive and negative samples
手写一个模拟的ReentrantLock
2022-07-07:原本数组中都是大于0、小于等于k的数字,是一个单调不减的数组, 其中可能有相等的数字,总体趋势是递增的。 但是其中有些位置的数被替换成了0,我们需要求出所有的把0替换的方案数量:
ROS from entry to mastery (IX) initial experience of visual simulation: turtlebot3
Handwriting a simulated reentrantlock