forked from logicchains/ArrayAccessBench
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CS2.cs
139 lines (112 loc) · 3.14 KB
/
CS2.cs
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
using System;
public class MemtestS{
private const int NUM_RECORDS = 50 * 1000 * 444;
private static CSMemoryTrade[] trades;
static void Main(){
trades = new CSMemoryTrade[NUM_RECORDS];
for (int i = 0; i < NUM_RECORDS; i++){
trades[i] = new CSMemoryTrade();
}
for (int i = 0; i < 5; i++){
perfRun(i);
}
}
private static void perfRun(int runNum){
long milliseconds = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
long start = milliseconds;
init();
long buyCost = 0;
long sellCost = 0;
for (int i = 0; i < NUM_RECORDS; i++){
if (trades[i].getSide() == 'B'){
buyCost += (trades[i].getPrice() * trades[i].getQuantity());
}
else{
sellCost += (trades[i].getPrice() * trades[i].getQuantity());
}
}
milliseconds = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
long end = milliseconds;
long duration = end - start;
System.Console.Write(runNum + " - duration " + duration + "ms\n");
System.Console.Write("buyCost = " + buyCost + " sellCost = " + sellCost + "\n");
}
public static void init()
{
for (int i = 0; i < NUM_RECORDS; i++){
trades[i].setTradeId(i);
trades[i].setClientId(1);
trades[i].setVenueCode(123);
trades[i].setInstrumentCode(321);
trades[i].setPrice(i);
trades[i].setQuantity(i);
trades[i].setSide((i & 1) == 0 ? 'B' : 'S');
}
}
private sealed class CSMemoryTrade
{
private long tradeId;
private long clientId;
private int venueCode;
private int instrumentCode;
private long price;
private long quantity;
private char side;
public long getTradeId()
{
return tradeId;
}
public void setTradeId(long tradeId)
{
this.tradeId = tradeId;
}
public long getClientId()
{
return clientId;
}
public void setClientId(long clientId)
{
this.clientId = clientId;
}
public int getVenueCode()
{
return venueCode;
}
public void setVenueCode(int venueCode)
{
this.venueCode = venueCode;
}
public int getInstrumentCode()
{
return instrumentCode;
}
public void setInstrumentCode(int instrumentCode)
{
this.instrumentCode = instrumentCode;
}
public long getPrice()
{
return price;
}
public void setPrice(long price)
{
this.price = price;
}
public long getQuantity()
{
return quantity;
}
public void setQuantity(long quantity)
{
this.quantity = quantity;
}
public char getSide()
{
return side;
}
public void setSide(char side)
{
this.side = side;
}
}
}