Mercurial > pub > ImplabNet
comparison MonoPlay/Program.cs @ 183:4f82e0f161c3 ref20160224
fixed DFA optimization, JSON is fully functional
| author | cin |
|---|---|
| date | Fri, 25 Mar 2016 02:49:02 +0300 |
| parents | 97fbbf816844 |
| children | d45bdf510514 |
comparison
equal
deleted
inserted
replaced
| 182:76e8f2ba12b8 | 183:4f82e0f161c3 |
|---|---|
| 1 using System; | 1 using System; |
| 2 using Implab; | 2 using Implab; |
| 3 using System.Threading.Tasks; | 3 using System.Threading.Tasks; |
| 4 using Implab.Formats.JSON; | |
| 5 using System.IO; | |
| 6 using System.Text.Json; | |
| 4 | 7 |
| 5 namespace MonoPlay { | 8 namespace MonoPlay { |
| 6 class MainClass { | 9 class MainClass { |
| 7 | 10 |
| 8 | 11 |
| 9 public static void Main(string[] args) { | 12 public static void Main(string[] args) { |
| 10 if (args == null) | 13 if (args == null) |
| 11 throw new ArgumentNullException("args"); | 14 throw new ArgumentNullException("args"); |
| 15 int t1, t2; | |
| 12 | 16 |
| 13 var t1 = Environment.TickCount; | 17 for (int i = 0; i < 2; i++) { |
| 18 t1 = Environment.TickCount; | |
| 19 int elements =0; | |
| 20 using (var reader = new JSONParser(File.OpenText("/home/sergey/temp/citylots.json"))) { | |
| 21 while (reader.Read()) | |
| 22 elements++; | |
| 23 } | |
| 14 | 24 |
| 15 DoWork().GetAwaiter().GetResult(); | 25 t2 = Environment.TickCount; |
| 26 Console.WriteLine("attempt {0} done: {1} ms, {2:.00} Mb, {3} GC, Elements: {4}",i+1, t2 - t1, GC.GetTotalMemory(false) / (1024*1024), GC.CollectionCount(0), elements ); | |
| 27 } | |
| 16 | 28 |
| 17 var t2 = Environment.TickCount; | 29 Console.WriteLine("Syste.Text.Json"); |
| 18 Console.WriteLine("done: {0} ms, {1:.00} Mb, {2} GC", t2 - t1, GC.GetTotalMemory(false) / (1024*1024), GC.CollectionCount(0) ); | 30 var paraser = new JsonParser(); |
| 31 for (int i = 0; i < 2; i++) { | |
| 32 t1 = Environment.TickCount; | |
| 33 using (var reader = File.OpenText("/home/sergey/temp/citylots.json")) { | |
| 34 paraser.Parse(reader); | |
| 35 } | |
| 19 | 36 |
| 20 } | 37 t2 = Environment.TickCount; |
| 38 Console.WriteLine("attempt {0} done: {1} ms, {2:.00} Mb, {3} GC, ",i+1, t2 - t1, GC.GetTotalMemory(false) / (1024*1024), GC.CollectionCount(0)); | |
| 39 } | |
| 21 | 40 |
| 22 static IPromise<int> DoItem(int x) { | |
| 23 //return Promise<int>.FromResult(x + 1); | |
| 24 var p = new Promise<int>(); | |
| 25 p.Resolve(x+1); | |
| 26 return p; | |
| 27 } | |
| 28 | 41 |
| 29 static async Task<int> DoWork() { | |
| 30 var c = 0; | |
| 31 for (int i = 0; i < 10000000; i++) | |
| 32 c = await DoItem(c); | |
| 33 return c; | |
| 34 } | 42 } |
| 35 | 43 |
| 36 } | 44 } |
| 37 } | 45 } |
