- Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathRuby.rb
More file actions
Latest commit
64 lines (56 loc) · 1.22 KB
/
Copy pathRuby.rb
File metadata and controls
64 lines (56 loc) · 1.22 KB
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
NUM_RECORDS=50 * 1000 * 444
classRubyMemTrade
attr_reader:tId,:cId,:vCode,:iCode,:price,:quantity,:side
definitialize(tId,cId,vCode,iCode,price,quantity,side)
@tradeId=tId
@clientId=cId
@venueCode=vCode
@instrumentCode=iCode
@price=price
@quantity=quantity
@side=side
end
deffromI(i)
@tradeId=i
@clientId=1
@venueCode=123
@instrumentCode=321
@price=i
@quantity=i
@side=if(i % 2 == 0)then'B'else'S'end
end
end
$trades =Array.new(NUM_RECORDS)
defprepareTrades()
foriin0..NUM_RECORDS
$trades[i]=(RubyMemTrade.new(0,0,0,0,0,0,'a'))
end
end
definitTrades()
foriin0..NUM_RECORDS
$trades[i].fromI(i)
end
end
defperfRun(runNum)
startT=Time.now()
initTrades()
buyCost=0
sellCost=0
foriin0..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.now()
duration=(endT - startT) * 1000
printf("%d - duration %d ms\n",runNum,duration)
printf("buyCost = %d sellCost = %d\n",buyCost,sellCost)
end
if__FILE__ == $0
prepareTrades()
foriin0..5
perfRun(i)
end
end