示例#1
0
        static async Task EventNextTest(int concurrent)
        {
            mCount = 0;
            IUserService henry = EventCenter.Create <IUserService>("henry");;
            IUserService nb    = EventCenter.Create <IUserService>("nb");;
            long         start = EventCenter.Watch.ElapsedMilliseconds;
            List <Task>  tasks = new List <Task>();

            for (int k = 0; k < concurrent; k++)
            {
                var task = Task.Run(async() =>
                {
                    for (int i = 0; i < mFors; i++)
                    {
                        var result = await henry.Income(i);
                        System.Threading.Interlocked.Increment(ref mCount);
                    }
                });
                tasks.Add(task);

                task = Task.Run(async() =>
                {
                    for (int i = 0; i < mFors; i++)
                    {
                        var result = await henry.Payout(i);
                        System.Threading.Interlocked.Increment(ref mCount);
                    }
                });
                tasks.Add(task);


                task = Task.Run(async() =>
                {
                    for (int i = 0; i < mFors; i++)
                    {
                        var result = await nb.Income(i);
                        System.Threading.Interlocked.Increment(ref mCount);
                    }
                });
                tasks.Add(task);

                task = Task.Run(async() =>
                {
                    for (int i = 0; i < mFors; i++)
                    {
                        var result = await nb.Payout(i);
                        System.Threading.Interlocked.Increment(ref mCount);
                    }
                });
                tasks.Add(task);
            }
            Task.WaitAll(tasks.ToArray());
            var henryAmount = await henry.Amount();

            var nbAmount = await nb.Amount();

            double usetime = EventCenter.Watch.ElapsedMilliseconds - start;

            Console.WriteLine($"EventNext concurrent{concurrent} use time:{usetime}|count:{mCount}|rps:{(mCount / usetime * 1000):####}|henry:{henryAmount}|nb:{nbAmount}");
        }
示例#2
0
 static void Main(string[] args)
 {
     EventCenter.Register(typeof(Program).Assembly);
     EventCenter.LogOutput += (o, e) =>
     {
         Console.WriteLine($"[{e.Type}]{e.Message}");
     };
     henry = EventCenter.Create <IUserService>("henry");
     nb    = EventCenter.Create <IUserService>("nb");
     Test();
     Console.Read();
 }