CLR via C# 讀書筆記 6-3 跨域訪問的性能問題
以下代碼演示了跨域訪問的性能問題
大約不跨域比跨域快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

浙公網安備 33010602011771號