comparison MonoPlay/Program.cs @ 151:ec91a6dfa5b3 v2

Added support for 'await' operator to promises
author cin
date Thu, 04 Feb 2016 02:43:05 +0300
parents 3258399cba83
children 97fbbf816844
comparison
equal deleted inserted replaced
150:3258399cba83 151:ec91a6dfa5b3
5 using System.Collections.Generic; 5 using System.Collections.Generic;
6 using System.Collections.Concurrent; 6 using System.Collections.Concurrent;
7 using System.Threading; 7 using System.Threading;
8 using Implab.JSON; 8 using Implab.JSON;
9 using System.IO; 9 using System.IO;
10 using System.Threading.Tasks;
10 11
11 namespace MonoPlay { 12 namespace MonoPlay {
12 class MainClass { 13 class MainClass {
13 14
14 15
16 if (args == null) 17 if (args == null)
17 throw new ArgumentNullException("args"); 18 throw new ArgumentNullException("args");
18 19
19 var t1 = Environment.TickCount; 20 var t1 = Environment.TickCount;
20 21
21 for(int i =0; i < 1000000; i++) 22 DoWork().GetAwaiter().GetResult();
22 using (var tw = new StringWriter()) {
23 var jw = new JSONWriter(tw);
24
25 jw.WriteValue("\r\nhere\tvalue\u0002\u0003");
26
27 //Console.WriteLine(tw);
28 }
29
30
31 23
32 var t2 = Environment.TickCount; 24 var t2 = Environment.TickCount;
33 Console.WriteLine("done: {0} ms, {1:.00} Mb, {2} GC", t2 - t1, GC.GetTotalMemory(false) / (1024*1024), GC.CollectionCount(0) ); 25 Console.WriteLine("done: {0} ms, {1:.00} Mb, {2} GC", t2 - t1, GC.GetTotalMemory(false) / (1024*1024), GC.CollectionCount(0) );
34 26
35 } 27 }
36 28
37 static void DoTest() { 29 static IPromise<int> DoItem(int x) {
30 return Promise<int>.FromResult(x + 1);
31 }
38 32
39 33 static async Task<int> DoWork() {
40 34 var c = 0;
35 for (int i = 0; i < 10000000; i++)
36 c = await DoItem(c);
37 return c;
41 } 38 }
42 39
43 } 40 }
44 } 41 }