Skip to content

Commit 99e67ef

Browse files
committed
Benchmark done in Tcl
A Tcl implementation of the benchmark. Run with tclsh (at least version 8.4 needed).
1 parent d4294c9 commit 99e67ef

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

Diff for: BenchmarkData.dat

+4
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,7 @@ Ruby
8383
ruby Ruby.rb
8484
Ruby.rb
8585
-
86+
Tcl
87+
-
88+
tclsh bench.tcl
89+
bench.tcl

Diff for: bench.tcl

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env tclsh8.6
2+
#
3+
#set NUM_RECORDS [expr {50 * 1000 * 444}]
4+
set NUM_RECORDS [expr {50 * 1000 * 50}]
5+
6+
proc initTrades {} {
7+
set recs $::NUM_RECORDS
8+
set trades [lrepeat $recs [list 1 2 3 4 5 6 7]]
9+
for {set i 0} {$i < $recs} {incr i} {
10+
if {$i % 2} {
11+
set side "B"
12+
} else {
13+
set side "S"
14+
}
15+
lset trades $i 0 $i
16+
lset trades $i 1 1
17+
lset trades $i 2 123
18+
lset trades $i 3 321
19+
lset trades $i 4 $i
20+
lset trades $i 5 $i
21+
lset trades $i 6 $side
22+
}
23+
return $trades
24+
}
25+
26+
proc perfRun {i} {
27+
set start [clock clicks -milliseconds]
28+
set trades [initTrades]
29+
set buyCost 0
30+
set sellCost 0
31+
32+
foreach trade $trades {
33+
if {[lindex $trade 6] eq "B"} {
34+
set buyCost [expr {$buyCost + [lindex $trade 4] * [lindex $trade 5]}]
35+
} else {
36+
set sellCost [expr {$sellCost + [lindex $trade 4] * [lindex $trade 5]}]
37+
}
38+
}
39+
set stop [clock clicks -milliseconds]
40+
set duration [expr {$stop - $start}]
41+
puts [format "%s - duration %d ms" $i $duration]
42+
puts [format "buyCost = %s sellCost = %s" $buyCost $sellCost]
43+
}
44+
45+
proc main {} {
46+
for {set i 0} {$i < 5} { incr i} {
47+
perfRun $i
48+
}
49+
}
50+
main ; #

0 commit comments

Comments
 (0)