洛克王国海德在哪,我心飞翔简谱,龙行qq空间
两段极为相似的代码,主要想看看过输与序列化过程两者的用时差异,结果10000次的调用,wcf用了11秒多,remoting用了5秒不到!
这是测试的源代码
remoting的服务端
public class remotcalc : marshalbyrefobject, icalc
{
public calcinfo calc(calcinfo pinfo)
{
calcinfo info = new calcinfo();
info.method = string.format("back_{0}", pinfo.method);
info.para1 = pinfo.para1;
info.para2 = pinfo.para2;
info.result = pinfo.result + 999;
return info;
}
}
wcf的服务端
public class wcfcalc : srv.interface.icalc { public calcinfo calc(calcinfo pinfo) { calcinfo info = new calcinfo(); info.method = string.format("back_{0}", pinfo.method); info.para1 = pinfo.para1; info.para2 = pinfo.para2; info.result = pinfo.result + 999; return info; } }
代码可以理解为一样的,以下的客户端,两客户端也可以视为一样的过程
wcf客户端
static void main(string[] args) { using(channelfactory<srv.interface.icalc> factory = new channelfactory<srv.interface.icalc>("calc2")) { srv.interface.icalc calc = factory.createchannel(); calcinfo info = new calcinfo(); info.method = "test"; console.writeline("press any key to run..."); console.readline(); int max = 10000; console.writeline("it's run..."); datetime start = datetime.now; for (int i = 0; i < max; i++) { calcinfo res = calc.calc(info); } timespan sp = datetime.now - start; console.writeline("run {0} times use {1}ms ", max, sp.totalmilliseconds); console.readline(); } }
remoting客户端
static void main(string[] args) { channelservices.registerchannel(new tcpclientchannel(), false); icalc remoteobj = (icalc)activator.getobject(typeof(icalc), "tcp://localhost:6666/calc"); calcinfo info = new calcinfo(); info.method = "test"; console.writeline("press any key to run..."); console.readline(); int max = 10000; datetime start = datetime.now; for (int i = 0; i < max; i++) { calcinfo res = remoteobj.calc(info); } timespan sp = datetime.now - start; console.writeline("run {0} times use {1}ms ", max, sp.totalmilliseconds); console.readline(); }
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Blazor server side 自家的一些开源的, 实用型项目的进度之 CEF客户端
.NET IoC模式依赖反转(DIP)、控制反转(Ioc)、依赖注入(DI)
vue+.netcore可支持业务代码扩展的开发框架 VOL.Vue 2.0版本发布
网友评论