-
Notifications
You must be signed in to change notification settings - Fork 8
/
Scala.scala
67 lines (57 loc) · 1.68 KB
/
Scala.scala
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
/*
Run with -J-Xmx2g option to increase heapsize
*/
class ScalaMemTrade(tId: Int, cId: Int, vCode: Int, iCode: Int, iPrice: Long, iQuantity: Long, sSide: Char) {
var tradeId: Int =tId
var clientId: Int =cId
var venueCode: Int =vCode
var instrumentCode: Int =iCode
var price: Long =iPrice
var quantity: Long =iQuantity
var side: Char =sSide
def fromI(i: Int) = {
tradeId=i
clientId=1
venueCode=123
instrumentCode=321
price=i
quantity=i
side = if (i % 2 == 0) 'B' else 'S';
}
}
object ScalaTrade {
val NUM_RECORDS: Int = 50 * 1000 * 444;
val trades: Array[ScalaMemTrade] = new Array[ScalaMemTrade](NUM_RECORDS);
def prepareTrades() : Unit = {
var i = 0
while (i < NUM_RECORDS) { trades(i) = new ScalaMemTrade(0,0,0,0,0,0,'a'); i+=1 }
}
def initTrades() : Unit = {
var i = 0
while (i < NUM_RECORDS) { trades(i).fromI(i); i+=1 }
}
def perfRun(runNum: Int): Unit = {
val startT: Long = System.currentTimeMillis()
var i = 0
initTrades()
var buyCost: BigInt = 0
var sellCost: BigInt = 0
while (i < NUM_RECORDS) {
if (trades(i).side == 'B')
buyCost += trades(i).price * trades(i).quantity
else
sellCost += trades(i).price * trades(i).quantity
i += 1
}
val endT: Long = System.currentTimeMillis()
val duration = (endT - startT)
printf("%d - duration %d ms\n", runNum, duration)
printf("buyCost = %d sellCost = %d\n", buyCost, sellCost)
}
def main(args: Array[String]) {
prepareTrades()
System.gc()
(0 to 5).map { i => System.gc(); printf("Run %d\n", i); perfRun(i) }
}
}
ScalaTrade.main(args)