/// <summary> /// 测试 /// </summary> private static void test() { int left = TcpInternalSimpleClientPerformance.Client.Left; AutoCSer.TestCase.TcpServerPerformance.IOpenSimpleServer client = AutoCSer.Net.TcpOpenSimpleServer.Emit.Client <AutoCSer.TestCase.TcpServerPerformance.IOpenSimpleServer> .Create(); using (AutoCSer.Net.TcpOpenSimpleServer.Emit.MethodClient methodClient = client as AutoCSer.Net.TcpOpenSimpleServer.Emit.MethodClient) { TcpInternalSimpleClientPerformance.Client.Start(TcpInternalSimpleClientPerformance.TestType.Synchronous, TcpInternalSimpleClientPerformance.Client.Count); for (int right = TcpInternalSimpleClientPerformance.Client.Count; right != 0;) { if (client.Add(left, --right).Value != left + right) { ++TcpInternalSimpleClientPerformance.Client.ErrorCount; } } stop(); } for (int threadCount = 2; threadCount <= 32; threadCount <<= 1) { TcpInternalSimpleClientPerformance.Client.ThreadCount = threadCount; TcpInternalSimpleClientPerformance.Client.Start(TcpInternalSimpleClientPerformance.TestType.Multithreading, TcpInternalSimpleClientPerformance.Client.Count * threadCount); for (int count = threadCount; count != 0; --count) { AutoCSer.Threading.ThreadPool.TinyBackground.Start(new ClientThread { Left = left, Right = TcpInternalSimpleClientPerformance.Client.Count }.Run); } Console.WriteLine("thread start " + threadCount.toString() + " end " + TcpInternalSimpleClientPerformance.Client.Time.ElapsedMilliseconds.toString() + "ms"); wait(); } }
/// <summary> /// /// </summary> internal void Run() { AutoCSer.TestCase.TcpServerPerformance.IOpenSimpleServer client = AutoCSer.Net.TcpOpenSimpleServer.Emit.Client <AutoCSer.TestCase.TcpServerPerformance.IOpenSimpleServer> .Create(); using (AutoCSer.Net.TcpOpenSimpleServer.Emit.MethodClient methodClient = client as AutoCSer.Net.TcpOpenSimpleServer.Emit.MethodClient) { int errorCount = 0; for (int left = Left, right = Right; right != 0;) { if (client.Add(left, --right).Value != left + right) { ++errorCount; } } Interlocked.Add(ref TcpInternalSimpleClientPerformance.Client.ErrorCount, errorCount); if (Interlocked.Decrement(ref TcpInternalSimpleClientPerformance.Client.ThreadCount) == 0) { TcpInternalSimpleClientPerformance.Client.Time.Stop(); TcpInternalSimpleClientPerformance.Client.WaitHandle.Set(); } } }