当前位置:网站首页>C# 泛型及性能比较
C# 泛型及性能比较
2022-07-07 22:17:00 【太阳的后裔】
什么是泛型?通俗的说就是不确定的类型。
什么时候用到泛型?当我们想要使用一个方法接收多种不同的类型的参数的时候我们常常能够用到。
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
结果
也就是说普通方法的性能大于指定类型的泛型方法大于未指定类型的泛型方法
偶尔真的很羡慕,羡慕某些人可以过目不忘,可以举一反三,而我同一份资料往往都要看多次才能真正的看懂。
但幸运的是,很多东西真的靠努力是可以改变和得到的,多敲敲代码,自己的技术就会慢慢提高,多跑跑步,身材就会变的更好,多听听书,自己也能满腹经纶。
加油,周末,你要越来越好,这不用别人看得出来,但是自己一定要知道。
边栏推荐
- 某马旅游网站开发(对servlet的优化)
- 自动化测试:Robot FrameWork框架90%的人都想知道的实用技巧
- LinkedBlockingQueue源码分析-新增和删除
- 搭建ADG过程中复制报错 RMAN-03009 ORA-03113
- 关于组织2021-2022全国青少年电子信息智能创新大赛西南赛区(四川)复赛的通知
- Emotional post station 010: things that contemporary college students should understand
- 去了字节跳动,才知道年薪 40w 的测试工程师有这么多?
- 【leetcode】day1
- Reading notes 004: Wang Yangming's quotations
- Basic learning of SQL Server -- creating databases and tables with the mouse
猜你喜欢

Is Zhou Hongyi, 52, still young?

【测试面试题】页面很卡的原因分析及解决方案

Basic learning of SQL Server -- creating databases and tables with code

【编程题】【Scratch二级】2019.12 绘制十个正方形

一鍵免費翻譯300多頁的pdf文檔

Fully automated processing of monthly card shortage data and output of card shortage personnel information

光流传感器初步测试:GL9306

Trust orbtk development issues 2022

Go learning notes (2) basic types and statements (1)
PostGIS learning
随机推荐
[question de programmation] [scratch niveau 2] oiseaux volants en décembre 2019
某马旅游网站开发(对servlet的优化)
爬虫实战(八):爬表情包
Open display PDF file in web page
一鍵免費翻譯300多頁的pdf文檔
52岁的周鸿祎,还年轻吗?
paddle入门-使用LeNet在MNIST实现图像分类方法二
Visual Studio Deployment Project - Create shortcut to deployed executable
STM32F1與STM32CubeIDE編程實例-旋轉編碼器驅動
Kubectl 好用的命令行工具:oh-my-zsh 技巧和窍门
Connect diodes in series to improve voltage withstand
Go learning notes (1) environment installation and hello world
52歲的周鴻禕,還年輕嗎?
用語雀寫文章了,功能真心强大!
The difference between -s and -d when downloading packages using NPM
How to measure whether the product is "just needed, high frequency, pain points"
Traduction gratuite en un clic de plus de 300 pages de documents PDF
SQL uses the in keyword to query multiple fields
[leetcode] 20. Valid brackets
35岁真就成了职业危机?不,我的技术在积累,我还越吃越香了