diff MonoPlay/Program.cs @ 125:f803565868a4 v2

improved performance of promises
author cin
date Thu, 15 Jan 2015 12:09:20 +0300
parents a336cb13c6a9
children e9e7940c7d98
line wrap: on
line diff
--- a/MonoPlay/Program.cs	Thu Jan 15 02:43:14 2015 +0300
+++ b/MonoPlay/Program.cs	Thu Jan 15 12:09:20 2015 +0300
@@ -11,109 +11,23 @@
             if (args == null)
                 throw new ArgumentNullException("args");
 
-            var q1 = new AsyncQueue<int>();
-            var q2 = new Queue<int>();
-
             const int count = 10000000;
 
-            int res1 = 0, res2 = 0;
             var t1 = Environment.TickCount;
 
-            AsyncPool.RunThread(
-                () => {
-                    for (var i = 0; i < count; i++)
-                        q1.Enqueue(1);
-                    Console.WriteLine("done writer #1: {0} ms", Environment.TickCount - t1);
-                },
-                () => {
-                    for (var i = 0; i < count; i++)
-                        q1.Enqueue(2);
-                    Console.WriteLine("done writer #2: {0} ms", Environment.TickCount - t1);
-                },
-                () => {
-                    int temp = 0;
-                    int i = 0;
-                    while (i < count)
-                        if (q1.TryDequeue(out temp)) {
-                            i++;
-                            res1 += temp;
-                        }
-                    Console.WriteLine("done reader #1: {0} ms", Environment.TickCount - t1);
-                },
-                () => {
-                    int temp = 0;
-                    int i = 0;
-                    while (i < count)
-                        if (q1.TryDequeue(out temp)) {
-                            i++;
-                            res2 += temp;
-                        }
-                    Console.WriteLine("done reader #2: {0} ms", Environment.TickCount - t1);
-                }
-            )
-                .Bundle()
-                .Join();
+            for (int i = 0; i < count; i++) {
+                var p = new Promise<int>();
+
+                p.On(x => {}).On(x => {});
 
-            Console.WriteLine("done: {0} ms, summ#1: {1}, summ#2: {2}, total: {3}, count: {4}", Environment.TickCount - t1, res1, res2, res1 + res2, count*2);
+                p.Resolve(i);
+
+            }
+
+           
 
             var t2 = Environment.TickCount;
-            Console.WriteLine("MTQueue: {0} ms", t2 - t1);
-
-            t1 = Environment.TickCount;
-
-            for (var i = 0; i < count * 2; i++)
-                q2.Enqueue(i);
-
-            for (var i = 0; i < count * 2; i++)
-                q2.Dequeue();
-
-            t2 = Environment.TickCount;
-            Console.WriteLine("Queue: {0} ms", t2 - t1);
-
-            q2 = new Queue<int>();
-
-            t1 = Environment.TickCount;
-
-         
-            AsyncPool.RunThread(
-                () => {
-                    for (var i = 0; i < count; i++)
-                        lock (q2)
-                            q2.Enqueue(i);
-                },
-                () => {
-                    for (var i = 0; i < count; i++)
-                        lock (q2)
-                            q2.Enqueue(i);
-                },
-                () => {
-                    for (int i = 0; i < count ;)
-                        lock (q2) {
-                            if (q2.Count == 0)
-                                continue;
-                            q2.Dequeue();
-                            i++;
-                        }
-
-                },
-                () => {
-                    for (int i = 0; i < count ;)
-                        lock (q2) {
-                            if (q2.Count == 0)
-                                continue;
-                            q2.Dequeue();
-                            i++;
-                        }
-
-                }
-            )
-                .Bundle()
-                .Join();
-
-
-
-            t2 = Environment.TickCount;
-            Console.WriteLine("Queue+Lock: {0} ms", t2 - t1);
+            Console.WriteLine("done: {0} ms, {1:.00} Mb, {2} GC", t2 - t1, GC.GetTotalMemory(false) / (1024*1024), GC.CollectionCount(0) );
 
         }
     }