示例#1
0
        static void CompareCounters2()
        {
            var winCounters      = new WinCounterFactory();
            var internalCounters = new InternalCounterFactory();

            var winAvCnt = winCounters.CreateSingleInstanceCategory("testCat2222", "").CreateAverageCountCounter("avCntTest", "");
            var intAvCnt = internalCounters.CreateSingleInstanceCategory("testCat2222", "").CreateAverageCountCounter("avCntTest", "");

            winCounters.InitAll();
            internalCounters.InitAll();


            Task.Run(() =>
            {
                Random rnd   = new Random();
                Stopwatch sw = Stopwatch.StartNew();
                for (int i = 0; i < 1000000000; i++)
                {
                    if (i % 100 < 50)
                    {
                        winAvCnt.RegisterValue(i % 100);
                        intAvCnt.RegisterValue(i % 100);
                    }
                    else
                    {
                        winAvCnt.RegisterValue(100 - i % 100);
                        intAvCnt.RegisterValue(100 - i % 100);
                    }
                    //if (i % 2 == 0)
                    //{
                    //    winAvCnt.RegisterValue(1000);
                    //    intAvCnt.RegisterValue(1000);
                    //}
                    //else
                    //{
                    //    winAvCnt.RegisterValue(0);
                    //    intAvCnt.RegisterValue(0);
                    //}

                    Thread.Sleep(10);

                    //while (sw.ElapsedMilliseconds < 100)
                    //    Thread.Sleep(0);

                    //sw.Restart();
                }
            });

            while (true)
            {
                double winVal = winAvCnt.CurrentValue;
                double intVal = intAvCnt.CurrentValue;

                Console.WriteLine("win = " + winVal.ToString() + ", int = " + intVal.ToString());
                Thread.Sleep(250);
            }
        }
示例#2
0
        static void CompareCounters()
        {
            var winCounters      = new WinCounterFactory();
            var internalCounters = new InternalCounterFactory();

            var winOpPerSec = winCounters.CreateSingleInstanceCategory("testCat1111", "").CreateOperationsPerSecondCounter("opCntTest", "");
            var intOpPerSec = internalCounters.CreateSingleInstanceCategory("testCat1111", "").CreateOperationsPerSecondCounter("opCntTest", "");

            winCounters.InitAll();
            internalCounters.InitAll();


            Task.Run(() =>
            {
                Random rnd   = new Random();
                Stopwatch sw = Stopwatch.StartNew();
                for (int i = 0; i < 1000000000; i++)
                {
                    //winOpPerSec.OperationFinished();
                    intOpPerSec.OperationFinished();

                    //while (sw.ElapsedMilliseconds < 100)
                    //    Thread.Sleep(0);

                    //sw.Restart();
                }
            });

            while (true)
            {
                double winVal = winOpPerSec.CurrentValue;
                double intVal = intOpPerSec.CurrentValue;

                Console.WriteLine("win = " + winVal.ToString() + ", int = " + intVal.ToString());
                Thread.Sleep(250);
            }
        }