-
Notifications
You must be signed in to change notification settings - Fork 8
/
FS2.fs
43 lines (38 loc) · 1.49 KB
/
FS2.fs
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
let NUM_RECORDS = 50 * 1000 * 444
type FSMemTrade = {
mutable TradeId : int64;
mutable ClientId : int64;
mutable VenueId : int32;
mutable InstrumentCode : int32;
mutable Price : int64;
mutable Quantity : int64;
mutable Side : char}
let trades : FSMemTrade array = Array.zeroCreate NUM_RECORDS
let prepareArray =
for i in 0 .. (NUM_RECORDS - 1) do
Array.set trades i {TradeId = (int64 0); ClientId = (int64 0); VenueId = (int32 0); InstrumentCode = (int32 0); Price = (int64 0); Quantity = (int64 0); Side = 'a'}
let initTrades() =
printfn "initiating trades"
for i in 0 .. (NUM_RECORDS - 1) do
trades.[i].TradeId <- (int64 i)
trades.[i].ClientId <- (int64 1)
trades.[i].VenueId <- 123
trades.[i].InstrumentCode <- 321
trades.[i].Price <- (int64 i)
trades.[i].Quantity <- (int64 i)
trades.[i].Side <- if (i%2 = 0) then 'S' else 'B'
let perfRun n =
let startT = System.DateTime.Now.Ticks / System.TimeSpan.TicksPerMillisecond
let mutable buyCost = (int64 0)
let mutable sellCost = (int64 0)
initTrades()
for i in 0 .. (NUM_RECORDS - 1) do
if (trades.[i].Side = 'B') then buyCost <- trades.[i].Price * trades.[i].Quantity else sellCost <- trades.[i].Price * trades.[i].Quantity
let endT = System.DateTime.Now.Ticks / System.TimeSpan.TicksPerMillisecond
let duration = endT - startT
printfn "%d - duration %d ms" n duration
printfn "buyCost = %O sellCost = %O" buyCost sellCost
let main =
prepareArray
for i in 0 .. 4 do
perfRun i