/// <summary> /// /// </summary> internal void Run() { using (AutoCSer.TestCase.TcpInternalSimpleServerPerformance.InternalSimpleServer.TcpInternalSimpleClient client = new AutoCSer.TestCase.TcpInternalSimpleServerPerformance.InternalSimpleServer.TcpInternalSimpleClient()) { int errorCount = 0; for (int left = Left, right = Right; right != 0;) { if (client.addSynchronous(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(); } } }
/// <summary> /// 测试 /// </summary> private static void test() { int left = Client.Left; using (AutoCSer.TestCase.TcpInternalSimpleServerPerformance.InternalSimpleServer.TcpInternalSimpleClient client = new AutoCSer.TestCase.TcpInternalSimpleServerPerformance.InternalSimpleServer.TcpInternalSimpleClient()) { Client.Start(TestType.Synchronous, Client.Count); for (int right = Client.Count; right != 0;) { if (client.addAsynchronous(left, --right).Value != left + right) { ++Client.ErrorCount; } } stop(); Client.Start(TestType.Asynchronous, Client.Count); for (int right = Client.Count; right != 0;) { if (client.addAsynchronous(left, --right).Value != left + right) { ++Client.ErrorCount; } } stop(); } for (int threadCount = 2; threadCount <= 32; threadCount <<= 1) { Client.ThreadCount = threadCount; Client.Start(TestType.Multithreading, Client.Count * threadCount); for (int count = threadCount; count != 0; --count) { AutoCSer.Threading.ThreadPool.TinyBackground.Start(new ClientThread { Left = left, Right = Client.Count }.Run); } Console.WriteLine("thread start " + threadCount.toString() + " end " + Client.Time.ElapsedMilliseconds.toString() + "ms"); wait(); } }