以下代码演示了跨域访问的性能问题
大约不跨域比跨域快100多倍....
代码
AppDomain newDomain = AppDomain.CreateDomain("remote application domain", null, null);
MarshalByRefType local = new MarshalByRefType();
MarshalByRefType remote = (MarshalByRefType)newDomain.CreateInstanceAndUnwrap(Assembly.GetEntryAssembly().FullName, "TestConsole.MarshalByRefType");
Stopwatch sw = null;
int length = 10000000;
int temp;
sw = Stopwatch.StartNew();
for (int i = 0; i < length; i++)
{
//local.SetValue(i);
temp=local.GetValue();
}
Console.WriteLine(sw.ElapsedMilliseconds);
sw = Stopwatch.StartNew();
for (int i = 0; i < length; i++)
{
//remote.SetValue(i);
temp = remote.GetValue();
}
Console.WriteLine(sw.ElapsedMilliseconds);
return;
test result in my machine:
101
17532