c#测试反射性能示例
时间:2021-12-19 23:13:47
Activator.CreateInstance和AssemblyCreateInstance性能测试
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using HelloWorld.ServiceReference1;
using System.Globalization;
using System.Reflection;
using Interface;
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
Stopwatch s = new Stopwatch();
Assembly a = Assembly.GetExecutingAssembly();
//foreach (var st in a.GetExportedTypes())
//{
// Console.WriteLine(st.Name);
//}
s.Reset();
s.Start();
Type t = a.GetType("HelloWorld.Test1");
Interface1 i2 = (Interface1)(Activator.CreateInstance(t));
Console.WriteLine((i2.Add(1, 2)));
s.Stop();
Console.WriteLine(s.Elapsed);
s.Reset();
s.Start();
Interface1 i = (Interface1)a.CreateInstance("HelloWorld.Test1");
Console.WriteLine((i.Add(1, 2)));
s.Stop();
Console.WriteLine(s.Elapsed);
}
}
public class Test1 : Interface1
{
public int Add(int a, int b)
{
return a + b;
}
}
public interface Interface1
{
int Add(int a, int b);
}
}
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
深入了解SparkSQL的运用及方法
![](https://img.aspxhome.com/file/2023/6/64126_0s.jpg)
intellij idea修改maven配置时总是恢复默认配置的解决方法idea版本(2020.2.x)
![](https://img.aspxhome.com/file/2023/5/89585_0s.png)
Spring中的bean概念介绍
![](https://img.aspxhome.com/file/2023/3/71863_0s.png)
浅谈Java中Collections.sort对List排序的两种方法
Java四种常用线程池的详细介绍
基于JDK8总结java中的interrupt
Java实现雪花算法的原理和实战教程
![](https://img.aspxhome.com/file/2023/6/94346_0s.png)
Java并发编程同步器CountDownLatch
![](https://img.aspxhome.com/file/2023/1/85491_0s.png)
java基础学习笔记之泛型
利用Java写一个学生管理系统
![](https://img.aspxhome.com/file/2023/1/61071_0s.jpg)
Android基于SoftReference缓存图片的方法
C#使用LINQ查询表达式的基本子句总结
![](https://img.aspxhome.com/file/2023/3/77253_0s.png)
C#在foreach遍历删除集合中元素的三种实现方法
![](https://img.aspxhome.com/file/2023/2/100132_0s.png)
Spring bean配置单例或多例模式方式
![](https://img.aspxhome.com/file/2023/3/63643_0s.jpg)
Spring Feign超时设置深入了解
![](https://img.aspxhome.com/file/2023/7/86727_0s.png)
Linux中Java开发常用软件安装方法总结
![](https://img.aspxhome.com/file/2023/2/85912_0s.png)
六款值得推荐的android(安卓)开源框架简介
Java+Swing实现五子棋游戏的示例代码
![](https://img.aspxhome.com/file/2023/9/66079_0s.jpg)
详解Spring Data Jpa 模糊查询的正确用法
MyBatis逆向⼯程的生成过程
![](https://img.aspxhome.com/file/2023/3/63313_0s.png)