当前位置:网站首页>C generic speed
C generic speed
2022-06-26 05:51:00 【self85】
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyGeneric
{
public class Monitor
{
static void Main(string[] args)
{
Show();
Console.ReadKey();
}
public static void Show()
{
Console.WriteLine("****************Monitor******************");
{
int iValue = 12345;
long commonSecond = 0;
long objectSecond = 0;
long genericSecond = 0;
const Int64 cycle = 1000000000;
{
Stopwatch watch = new Stopwatch();
watch.Start();
for (int i = 0; i < cycle; i++)
{
ShowInt(iValue);
}
watch.Stop();
commonSecond = watch.ElapsedMilliseconds;
}
{
Stopwatch watch = new Stopwatch();
watch.Start();
for (int i = 0; i < cycle; i++)
{
ShowObject(iValue);
}
watch.Stop();
objectSecond = watch.ElapsedMilliseconds;
}
{
Stopwatch watch = new Stopwatch();
watch.Start();
for (int i = 0; i < cycle; i++)
{
Show<int>(iValue);
}
watch.Stop();
genericSecond = watch.ElapsedMilliseconds;
}
Console.WriteLine("commonSecond={0}\r\n objectSecond={1}\r\n genericSecond={2}\r\n"
, 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
}
}


As can be seen from the results : Generic methods have the highest performance , Next is the common method ,object The method has the lowest performance .
边栏推荐
猜你喜欢

通俗易懂的从IDE说起,再谈谈小程序IDE

Bingc (inheritance)
Posting - don't get lost in the ocean of Technology

Bubble sort

pytorch(网络模型)

Consul service registration and discovery

How to use the tablet as the second extended screen of the PC

REUSE_ ALV_ GRID_ Display event implementation (data_changed)

电商借助小程序技术发力寻找增长突破口

Implementation of third-party wechat authorized login for applet
随机推荐
写在父亲节前
旧情书
Daily production training report (17)
kolla-ansible部署openstack yoga版本
睛天霹雳的消息
Gram matrix
DOM文档
Explore small program audio and video calls and interactive live broadcast from New Oriental live broadcast
Pytorch (environment, tensorboard, transforms, torchvision, dataloader)
Describe an experiment of Kali ARP in LAN
RIA想法
从新东方直播来探究下小程序音视频通话及互动直播
About abstact and virtual
ZigBee learning in simple terms lesson 3 external interruption
Using Jenkins to perform testng+selenium+jsup automated tests and generate extendreport test reports
Day2- syntax basis and variables
[PHP] PHP two-dimensional array is sorted by multiple fields
Use jedis to monitor redis stream to realize message queue function
Could not get unknown property ‘*‘ for SigningConfig container of type org. gradle. api. internal
Bubble sort