forked from logicchains/ArrayAccessBench
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Julia.jl
62 lines (52 loc) · 1.2 KB
/
Julia.jl
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
const NUM_RECORDS = 50 * 1000 * 444
type JuliaMemTrade
tradeId::Int64
clientId::Int64
venueCode::Int32
instrumentCode::Int32
price::Int64
quantity::Int64
side::Char
end
function initTrades(trades)
@inbounds for i in 1:NUM_RECORDS
trades[i].tradeId = i
trades[i].clientId = 1
trades[i].venueCode = int32(123)
trades[i].instrumentCode = int32(321)
trades[i].price = i
trades[i].quantity = i
if (i % 2) == 0
trades[i].side = 'B'
else
trades[i].side = 'S'
end
end
end
function perfRun(trades, runNum)
startT = time()
initTrades(trades)
buyCost::Int64 = 0
sellCost::Int64 = 0
@inbounds for i in 1:NUM_RECORDS
if trades[i].side == 'B'
buyCost += trades[i].price * trades[i].quantity
else
sellCost += trades[i].price * trades[i].quantity
end
end
endT = time()
duration = endT - startT
@printf "%d - duration %d ms\n" runNum (duration * 1000)
@printf "buyCost = %d sellCost = %d\n" buyCost sellCost
end
function main()
trades = Array(JuliaMemTrade,NUM_RECORDS)
for i in 1:NUM_RECORDS
trades[i] = JuliaMemTrade(0,0,0,0,0,0,'a')
end
for i in 1:5
perfRun(trades, i)
end
end
main()