Mercurial > pub > ImplabNet
diff Implab.Playground/Program.cs @ 255:b00441e04738 v3
Adde workaround to the behaviour of the logical operations stack in conjuction
with async/await methods
author | cin |
---|---|
date | Wed, 04 Apr 2018 15:38:48 +0300 |
parents | 302ca905c19e |
children | 547a2fc0d93e |
line wrap: on
line diff
--- a/Implab.Playground/Program.cs Mon Feb 12 17:03:49 2018 +0300 +++ b/Implab.Playground/Program.cs Wed Apr 04 15:38:48 2018 +0300 @@ -1,4 +1,5 @@ -using Implab.Formats.Json; +using Implab.Diagnostics; +using Implab.Formats.Json; using Implab.Parallels; using Implab.Xml; using System; @@ -13,80 +14,42 @@ using System.Xml.Serialization; namespace Implab.Playground { + using System.Diagnostics; + using System.Runtime.Remoting.Messaging; + using static Trace<Program>; + public class Program { - static void EnqueueRange<T>(ConcurrentQueue<T> q, T[] data, int offset, int len) { - for (var i = offset; i < offset + len; i++) - q.Enqueue(data[i]); - } + static void Main(string[] args) { + var listener = new SimpleTraceListener(Console.Out); + + var source = Trace<Program>.TraceSource; + source.Switch.Level = SourceLevels.All; - static bool TryDequeueRange<T>(ConcurrentQueue<T> q,T[] buffer,int offset, int len, out int actual) { - actual = 0; - T res; - while(q.TryDequeue(out res)) { - buffer[offset + actual] = res; - actual++; - if (actual == len) - break; - } - return actual != 0; - } + source.Listeners.Add(listener); + + var t = Environment.TickCount; - static void EnqueueRange<T>(SimpleAsyncQueue<T> q, T[] data, int offset, int len) { - for (var i = offset; i < offset + len; i++) - q.Enqueue(data[i]); - } + Main().Wait(); - static bool TryDequeueRange<T>(SimpleAsyncQueue<T> q, T[] buffer, int offset, int len, out int actual) { - actual = 0; - T res; - while (q.TryDequeue(out res)) { - buffer[offset + actual] = res; - actual++; - if (actual == len) - break; - } - return actual != 0; + Console.WriteLine($"Done: {Environment.TickCount - t} ms"); + Console.ReadKey(); } - static void EnqueueRange<T>(AsyncQueue<T> q, T[] data, int offset, int len) { - for (var i = offset; i < offset + len; i++) - q.Enqueue(data[i]); + static async Task Main() { + using (LogicalOperation(nameof(Main))) { + Log("Start"); + await SomeAsync(); + Log("End"); + } } - static bool TryDequeueRange<T>(AsyncQueue<T> q, T[] buffer, int offset, int len, out int actual) { - actual = 0; - T res; - while (q.TryDequeue(out res)) { - buffer[offset + actual] = res; - actual++; - if (actual == len) - break; + static async Task SomeAsync() { + using (LogicalOperation(nameof(SomeAsync))) { + Log("Do prepare"); + await Task.Yield(); + Log("Yield"); } - return actual != 0; - } - - - /*static void EnqueueRange<T>(AsyncQueue<T> q, T[] data, int offset, int len) { - q.EnqueueRange(data, offset, len); - } - - static bool TryDequeueRange<T>(AsyncQueue<T> q, T[] buffer, int offset, int len, out int actual) { - return q.TryDequeueRange(buffer, offset, len, out actual); - }*/ - - - static void Main(string[] args) { - - var t = Environment.TickCount; - using (var reader = JsonReader.Create("e:\\citylots.json")) { - while (reader.Read()) { - } - } - - Console.WriteLine($"JsonReader: {Environment.TickCount - t} ms"); - - Console.WriteLine("done"); } } }