示例#1
0
        private static void GetOrAddFuncBenchRndCD()
        {
            var dict = new Concurrent.ConcurrentDictionary <int, string>();
            var cnt  = new Counter32();

            var benchmarkName = "======== Random GetOrAdd Func Concurrent 1M int->string Ops/sec:";

            Action <int, int> act = (i, threadBias) =>
            {
                // get some random index in [0, 1000000]
                int randomIndex = GetRandomIndex(i, threadBias, 1000000);
                dict.GetOrAdd(randomIndex, (_) => "qq");

                // after making about 1000000 adds, start with a new table
                var c = cnt;
                c.Increment();
                if (Every8K(i) && c.Value > 1000000)
                {
                    if (Interlocked.CompareExchange(ref cnt, new Counter32(), c) == c)
                    {
                        dict = new Concurrent.ConcurrentDictionary <int, string>();
                    }
                }
            };

            RunBench(benchmarkName, act);
        }
示例#2
0
        private static void GetBenchCD_int()
        {
            var dict = new Concurrent.ConcurrentDictionary <int, int>();

            Parallel.For(0, 100000, (i) => dict[i] = i);
            Parallel.For(0, 100000, (i) => { var dummy = dict[i]; });

            var benchmarkName = "======== Get Concurrent int->int 1M Ops/sec:";

            Action <int, int> act = (i, threadBias) => { var dummy = dict[i % 100000]; };

            RunBench(benchmarkName, act);
        }
示例#3
0
        private static void WriteBenchRndCD()
        {
            var dict = new Concurrent.ConcurrentDictionary <int, string>();

            var benchmarkName = "======== Random Write Concurrent 1M int->string Ops/sec:";

            Action <int, int> act = (i, threadBias) =>
            {
                // get some random index in [0, 1000000]
                int randomIndex = GetRandomIndex(i, threadBias, 1000000);
                dict[randomIndex] = "qq";
                dict[randomIndex] = "aa";
            };

            RunBench(benchmarkName, act);
        }
示例#4
0
        private static void GetBenchCDObj()
        {
            var dict = new Concurrent.ConcurrentDictionary<object, string>();

            var keys = new string[200000];
            for (int i = 0; i < keys.Length; i++) keys[i] = i.ToString();

            Parallel.For(0, 100000, (i) => dict[keys[i]] = i.ToString());
            Parallel.For(0, 100000, (i) => { var dummy = dict[keys[i]]; });

            var benchmarkName = "======== Get Concurrent 1M Ops/sec:";

            Action<int, int> act = (i, threadBias) => { var dummy = dict[keys[i % 100000]]; };

            RunBench(benchmarkName, act);
        }
示例#5
0
        private static void GetBenchRndCD()
        {
            var dict = new Concurrent.ConcurrentDictionary <int, string>();

            Parallel.For(0, 100000, (i) => dict[i] = "qq");
            Parallel.For(0, 100000, (i) => { var dummy = dict[i]; });

            var benchmarkName = "======== Random Get Concurrent 1M int->string Ops/sec:";

            Action <int, int> act = (i, threadBias) =>
            {
                string dummy;
                int    randomIndex = GetRandomIndex(i, threadBias, 100000);
                dict.TryGetValue(randomIndex, out dummy);
            };

            RunBench(benchmarkName, act);
        }
示例#6
0
        static void Main(string[] args)
        {
            StandardC.ArrayList standardArrayList = new StandardC.ArrayList();
            StandardC.Hashtable standardHashtable = new StandardC.Hashtable();
            StandardC.Queue     standardQueue     = new StandardC.Queue();
            StandardC.Stack     standardStack     = new StandardC.Stack();

            Generic.Dictionary <int, string> genericDictionary = new Generic.Dictionary <int, string>();
            Generic.List <int>  genericList  = new Generic.List <int>();
            Generic.Queue <int> genericQueue = new Generic.Queue <int>();
            Generic.SortedList <int, string> genericSortedList = new Generic.SortedList <int, string>();
            Generic.Stack <int> genericStack = new Generic.Stack <int>();

            Concurrent.BlockingCollection <int>           concurrentBlockingCollection = new Concurrent.BlockingCollection <int>();
            Concurrent.ConcurrentDictionary <int, string> concurrentDictionary         = new Concurrent.ConcurrentDictionary <int, string>();
            Concurrent.ConcurrentQueue <int> concurrentQueue = new Concurrent.ConcurrentQueue <int>();
            Concurrent.ConcurrentStack <int> concurrentStack = new Concurrent.ConcurrentStack <int>();

            Console.WriteLine("Hello World!");
        }
示例#7
0
        private static void SingleThreadedSequentialAddWithGapsCD()
        {
            var dict = new Concurrent.ConcurrentDictionary <int, int>();

            for (var i = 0; i < 8; ++i)
            {
                Stopwatch sw  = Stopwatch.StartNew();
                var       key = (i + 1) * 50_000_000;

                for (var j = 0; j < 10_000_000; ++j)
                {
                    dict.TryAdd(key + j, j);
                }

                sw.Stop();
                System.Console.Write(sw.ElapsedMilliseconds + " ");

                GC.Collect();
            }

            System.Console.WriteLine();
        }