-
Notifications
You must be signed in to change notification settings - Fork 259
Expand file tree
/
Copy pathtest.cs
More file actions
75 lines (63 loc) · 1.88 KB
/
test.cs
File metadata and controls
75 lines (63 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using Newtonsoft.Json;
namespace Test
{
class Program
{
public class Coordinate
{
public double X { get; set; }
public double Y { get; set; }
public double Z { get; set; }
}
public class Root
{
public List<Coordinate> Coordinates { get; set; }
}
static void ParseJson(string text)
{
var sw = Stopwatch.StartNew();
var root = JsonConvert.DeserializeObject<Root>(text);
double x = 0;
double y = 0;
double z = 0;
int count = 0;
foreach(var c in root.Coordinates)
{
count += 1;
x += c.X;
y += c.Y;
z += c.Z;
};
Console.WriteLine("{0}\n{1}\n{2}", x/count, y/count, z/count);
sw.Stop();
Console.WriteLine("time: {0}s", sw.Elapsed.TotalSeconds);
}
private static void Notify(string msg) {
try {
using (var s = new System.Net.Sockets.TcpClient("localhost", 9001)) {
var data = System.Text.Encoding.UTF8.GetBytes(msg);
s.Client.Send(data);
}
} catch {
// standalone usage
}
}
static void Main(string[] args)
{
var text = File.ReadAllText("/tmp/1.json");
for (int i = 0; i < 4; i++)
{
ParseJson(text);
}
var runtime = Type.GetType("Mono.Runtime") != null ? "Mono" : ".NET Core";
Notify($"C# {runtime}\t{Process.GetCurrentProcess().Id}");
ParseJson(text);
Notify("stop");}
}
}