标签:localhost lan turn for log get test ann oid
两段极为相似的代码,主要想看看过输与序列化过程两者的用时差异,结果10000次的调用,WCF用了11秒多,remoting用了5秒不到!
这是测试的源代码
WCF的服务端
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; } }
Remoting的服务端
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(); }
标签:localhost lan turn for log get test ann oid
原文地址:https://www.cnblogs.com/kevin-Y/p/10018168.html