annotate Implab.Playground/Program.cs @ 247:fb70574741a1 v3

working on promises
author cin
date Fri, 26 Jan 2018 18:46:27 +0300
parents 302ca905c19e
children b00441e04738
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
229
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents:
diff changeset
1 using Implab.Formats.Json;
233
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
2 using Implab.Parallels;
229
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents:
diff changeset
3 using Implab.Xml;
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents:
diff changeset
4 using System;
233
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
5 using System.Collections.Concurrent;
229
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents:
diff changeset
6 using System.Collections.Generic;
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents:
diff changeset
7 using System.IO;
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents:
diff changeset
8 using System.Linq;
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents:
diff changeset
9 using System.Text;
233
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
10 using System.Threading;
229
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents:
diff changeset
11 using System.Threading.Tasks;
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents:
diff changeset
12 using System.Xml;
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents:
diff changeset
13 using System.Xml.Serialization;
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents:
diff changeset
14
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents:
diff changeset
15 namespace Implab.Playground {
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents:
diff changeset
16 public class Program {
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents:
diff changeset
17
233
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
18 static void EnqueueRange<T>(ConcurrentQueue<T> q, T[] data, int offset, int len) {
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
19 for (var i = offset; i < offset + len; i++)
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
20 q.Enqueue(data[i]);
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
21 }
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
22
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
23 static bool TryDequeueRange<T>(ConcurrentQueue<T> q,T[] buffer,int offset, int len, out int actual) {
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
24 actual = 0;
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
25 T res;
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
26 while(q.TryDequeue(out res)) {
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
27 buffer[offset + actual] = res;
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
28 actual++;
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
29 if (actual == len)
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
30 break;
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
31 }
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
32 return actual != 0;
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
33 }
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
34
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
35 static void EnqueueRange<T>(SimpleAsyncQueue<T> q, T[] data, int offset, int len) {
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
36 for (var i = offset; i < offset + len; i++)
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
37 q.Enqueue(data[i]);
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
38 }
229
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents:
diff changeset
39
233
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
40 static bool TryDequeueRange<T>(SimpleAsyncQueue<T> q, T[] buffer, int offset, int len, out int actual) {
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
41 actual = 0;
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
42 T res;
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
43 while (q.TryDequeue(out res)) {
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
44 buffer[offset + actual] = res;
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
45 actual++;
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
46 if (actual == len)
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
47 break;
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
48 }
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
49 return actual != 0;
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
50 }
229
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents:
diff changeset
51
233
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
52 static void EnqueueRange<T>(AsyncQueue<T> q, T[] data, int offset, int len) {
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
53 for (var i = offset; i < offset + len; i++)
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
54 q.Enqueue(data[i]);
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
55 }
229
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents:
diff changeset
56
233
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
57 static bool TryDequeueRange<T>(AsyncQueue<T> q, T[] buffer, int offset, int len, out int actual) {
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
58 actual = 0;
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
59 T res;
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
60 while (q.TryDequeue(out res)) {
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
61 buffer[offset + actual] = res;
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
62 actual++;
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
63 if (actual == len)
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
64 break;
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
65 }
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
66 return actual != 0;
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
67 }
234
8dd666e6b6bf Added implab nuget spec
cin
parents: 233
diff changeset
68
233
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
69
234
8dd666e6b6bf Added implab nuget spec
cin
parents: 233
diff changeset
70 /*static void EnqueueRange<T>(AsyncQueue<T> q, T[] data, int offset, int len) {
233
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
71 q.EnqueueRange(data, offset, len);
229
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents:
diff changeset
72 }
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents:
diff changeset
73
233
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
74 static bool TryDequeueRange<T>(AsyncQueue<T> q, T[] buffer, int offset, int len, out int actual) {
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
75 return q.TryDequeueRange(buffer, offset, len, out actual);
234
8dd666e6b6bf Added implab nuget spec
cin
parents: 233
diff changeset
76 }*/
233
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
77
d6fe09f5592c Improved AsyncQueue
cin
parents: 229
diff changeset
78
229
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents:
diff changeset
79 static void Main(string[] args) {
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents:
diff changeset
80
236
302ca905c19e JsonReader optimizations
cin
parents: 234
diff changeset
81 var t = Environment.TickCount;
302ca905c19e JsonReader optimizations
cin
parents: 234
diff changeset
82 using (var reader = JsonReader.Create("e:\\citylots.json")) {
302ca905c19e JsonReader optimizations
cin
parents: 234
diff changeset
83 while (reader.Read()) {
302ca905c19e JsonReader optimizations
cin
parents: 234
diff changeset
84 }
302ca905c19e JsonReader optimizations
cin
parents: 234
diff changeset
85 }
302ca905c19e JsonReader optimizations
cin
parents: 234
diff changeset
86
302ca905c19e JsonReader optimizations
cin
parents: 234
diff changeset
87 Console.WriteLine($"JsonReader: {Environment.TickCount - t} ms");
229
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents:
diff changeset
88
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents:
diff changeset
89 Console.WriteLine("done");
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents:
diff changeset
90 }
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents:
diff changeset
91 }
5f7a3e1d32b9 JsonXmlReader performance tuning
cin
parents:
diff changeset
92 }