Exemple #1
0
        private static void Test4()
        {
            var v = Rand.NextBytes(32);

            Console.WriteLine(v.ToBase64());

            ICache ch = null;

            //ICache ch = new DbCache();
            //ch.Set(key, v);
            //v = ch.Get<Byte[]>(key);
            //Console.WriteLine(v.ToBase64());
            //ch.Remove(key);

            Console.Clear();

            Console.Write("选择要测试的缓存:1,MemoryCache;2,DbCache;3,Redis ");
            var select = Console.ReadKey().KeyChar;

            switch (select)
            {
            case '1':
                ch = new MemoryCache();
                break;

            case '3':
                var rds = new Redis("127.0.0.1", null, 9)
                {
                    Counter = new PerfCounter(),
                    Tracer  = new DefaultTracer {
                        Log = XTrace.Log
                    },
                };
                ch = rds;
                break;
            }

            var mode = false;

            Console.WriteLine();
            Console.Write("选择测试模式:1,顺序;2,随机 ");
            if (Console.ReadKey().KeyChar != '1')
            {
                mode = true;
            }

            var batch = 0;

            Console.WriteLine();
            Console.Write("选择输入批大小[0]:");
            batch = Console.ReadLine().ToInt();

            Console.Clear();

            //var batch = 0;
            //if (mode) batch = 1000;

            var rs = ch.Bench(mode, batch);

            XTrace.WriteLine("总测试数据:{0:n0}", rs);
            if (ch is Redis rds2)
            {
                XTrace.WriteLine(rds2.Counter + "");
            }
        }