调用静态类的静态方法与通过接口(interface)调用对应方法的性能比较会是怎样的呢?有人进行过测试或统计么?
解决方案 »
- 指定类型转换无效。
- ASP.NET Response.Redirect 后Session 丢失问题,求助!
- Oracle 的事务语句?
- webpart
- 请问VS2005能否在Wap开发中上传文件呀!
- InitializeComponent()中注册的控件事件莫名其妙的消失!!!
- 关于条件为真,退出到指定循环体中(在线等)
- 站点安装、部署、配置、系统配置管理,软件项目产品化,减少项目人员在配置站点花去的时间,也方便管理系统自身系统参数的配置。希望能给点意见。
- 小女子求救:如何读取AD用户GUID
- 请问谁有。NET的BBS源程序,后台是SQL的!谢谢
- 使用ASP.NET遇到的怪事!!!
- 无法获取页面的问题!!!
------------------------------------------------------------------------------
/// <summary>
/// 静态方法测试类
/// </summary>
public class TestStatic
{
public static string Test()
{
string ret = "";
for(int i = 0;i < 100; i ++)
{
ret += "Test" + i + "<br>";
}
return ret;
}
}
/// TestInterface 的摘要说明。
/// </summary>
public interface TestInterface
{
string Test();
}--------------------------------------------------------
/// <summary>
/// TestClass 的摘要说明。
/// </summary>
public class TestClass:TestInterface
{
public TestClass()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
#region TestInterface 成员 public string Test()
{
string ret = "";
for(int i = 0;i < 100; i ++)
{
ret += "Test" + i + "<br>";
}
return ret;
} #endregion
}
{
Response.Write("C-S<br>");
int s_total = 0;
int c_total = 0;
for(int i = 0; i < 1000; i ++)
{
int s = TestClassMethod(i);
int c = TestStaticMethod(i);
s_total += s;
c_total += c;
if(s > 0 || c > 0)
{
Response.Write(c.ToString() + "-" + s.ToString() + "<br>");
}
}
Response.Write("----------------<br>");
Response.Write(c_total.ToString() + "-" + s_total.ToString() + "<br>");
} private int TestStaticMethod(int sort)
{
int start = System.Environment.TickCount;
TestStatic.Test();
int end = System.Environment.TickCount;
return end - start;
} private int TestClassMethod(int sort)
{
int start = System.Environment.TickCount;
TestInterface test = new TestClass();
test.Test();
int end = System.Environment.TickCount;
return end - start;
}