forked from kostya/benchmarks
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.tcl
58 lines (48 loc) · 1.55 KB
/
test.tcl
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
package require Tcl 8.6
proc main {} {
foreach fixture {{"hello" "aGVsbG8="} {"world" "d29ybGQ="}} {
set src [lindex $fixture 0]
set dst [lindex $fixture 1]
set encoded [binary encode base64 $src]
if {$encoded != $dst} {
puts stderr [format "%s != %s" $encoded $dst]
exit 1
}
set decoded [binary decode base64 $dst]
if {$decoded != $src} {
puts stderr [format "%s != %s" $decoded $src]
exit 1
}
}
set STR_SIZE 131072
set TRIES 8192
set str [string repeat a $STR_SIZE]
set encoded [binary encode base64 $str]
set decoded [binary decode base64 $encoded]
notify [format "%s\t%d" "Tcl" [pid]]
set t [clock milliseconds]
set s_encoded 0
for {set i 0} {$i < $TRIES} {incr i} {
incr s_encoded [string length [binary encode base64 $str]]
}
set t_encoded [expr { ([clock milliseconds] - $t) / 1000.0 }]
set t [clock milliseconds]
set s_decoded 0
for {set i 0} {$i < $TRIES} {incr i} {
incr s_decoded [string length [binary decode base64 $encoded]]
}
set t_decoded [expr { ([clock milliseconds] - $t) / 1000.0 }]
notify "stop"
puts "encode [string range $str 0 4]... to [string range $str 0 4]...: $s_encoded, $t_encoded"
puts "decode [string range $encoded 0 4]... to [string range $decoded 0 4]...: $s_decoded, $t_decoded"
}
proc notify msg {
catch {
set sock [socket "localhost" 9001]
puts $sock $msg
close $sock
}
}
apply {{} {
main
}}