forked from logicchains/ArrayAccessBench
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Java3.java
147 lines (119 loc) · 3.31 KB
/
Java3.java
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
140
141
142
143
144
145
146
147
import java.math.BigInteger;
public class Java3
{
private static final int NUM_RECORDS = 50 * 1000 * 444;
private static JavaMemoryTrade[] trades;
public static void main(final String[] args)
{
trades = new JavaMemoryTrade[NUM_RECORDS];
for (int i = 0; i < NUM_RECORDS; i++)
{
trades[i]= new JavaMemoryTrade();
}
for (int i = 0; i < 5; i++)
{
System.gc();
perfRun(i);
}
}
private static void perfRun(final int runNum)
{
long start = System.currentTimeMillis();
init();
BigInteger buyCost = BigInteger.valueOf(0);
BigInteger sellCost = BigInteger.valueOf(0);
for (int i = 0; i < NUM_RECORDS; i++)
{
if (trades[i].getSide() == 'B')
{
buyCost = buyCost.add(BigInteger.valueOf(trades[i].getPrice() * trades[i].getQuantity() ) );
}
else
{
sellCost = sellCost.add(BigInteger.valueOf(trades[i].getPrice() * trades[i].getQuantity() ) );
}
}
long duration = System.currentTimeMillis() - start;
System.out.println(runNum + " - duration " + duration + "ms");
System.out.println("buyCost = " + buyCost + " sellCost = " + sellCost);
}
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 static class JavaMemoryTrade
{
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(final long tradeId)
{
this.tradeId = tradeId;
}
public long getClientId()
{
return clientId;
}
public void setClientId(final long clientId)
{
this.clientId = clientId;
}
public int getVenueCode()
{
return venueCode;
}
public void setVenueCode(final int venueCode)
{
this.venueCode = venueCode;
}
public int getInstrumentCode()
{
return instrumentCode;
}
public void setInstrumentCode(final int instrumentCode)
{
this.instrumentCode = instrumentCode;
}
public long getPrice()
{
return price;
}
public void setPrice(final long price)
{
this.price = price;
}
public long getQuantity()
{
return quantity;
}
public void setQuantity(final long quantity)
{
this.quantity = quantity;
}
public char getSide()
{
return side;
}
public void setSide(final char side)
{
this.side = side;
}
}
}