Example #1
0
        public void TestCalculateOverhead()
        {
            const int amount = 1000;

            var pool = new WorkerPool(15);
            var c    = new Dictionary <string, int> {
                ["count"] = 0
            };

            pool.AddLockedTasks(() => { c["count"]++; }, amount);

            var sw = new Stopwatch();

            pool.Start();

            sw.Start();
            while (!pool.IsJobQueueEmpty)
            {
            }
            sw.Stop();

            Debug.WriteLine("Multi-threaded Ticks Init (ns): " + sw.ElapsedNs());

            pool.AddLockedTasks(() => { c["count"]++; }, amount);

            sw.Restart();
            while (!pool.IsJobQueueEmpty)
            {
            }
            sw.Stop();

            Debug.WriteLine("Multi-threaded Ticks Spun (ns): " + sw.ElapsedNs());

            var x = new Dictionary <string, int> {
                ["count"] = 0
            };

            sw.Restart();
            var i = 0;

            while (i < amount)
            {
                x["count"]++;
                i++;
            }
            sw.Stop();

            Debug.WriteLine("Single-threaded Ticks (ns): " + sw.ElapsedTicks * 100);
        }
Example #2
0
        public void TestConsistency()
        {
            const int amount = 1000;

            var pool = new WorkerPool();

            var c = new Dictionary <string, int> {
                ["count"] = 0
            };

            pool.AddLockedTasks(() => { c["count"]++; }, amount);

            var sw = new Stopwatch();

            pool.Start();

            sw.Start();
            pool.SpinWaitUntilComplete();
            sw.Stop();

            Debug.WriteLine("Multi-threaded Ticks Init (ns): " + sw.ElapsedTicks * 100);

            Assert.IsTrue(c["count"] == amount);
        }