blob: 037fc8e2df1d059ca92cd103f47683c597cb5091 (
plain)
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
|
source testing.tcl
test regexp-1.1 {effect of caching} {
set filedata {BEGIN_TABLE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; END_TABLE}
# Note: use 2 REs because often libc will cache a single regcomp() result
# t1 should be faster because the compiled re can be cached.
set re1 "END_TABLE"
set re2 "BEGIN_TABLE"
set t1 [time {
regexp -inline -all $re1 $filedata
regexp -inline -all $re2 $filedata
} 10000]
# t2 should be slower since the re's need to be recompiled every time
set t2 [time {
set re1 END
append re1 _TABLE
regexp -inline -all $re1 $filedata
set re2 BEGIN
append re2 _TABLE
regexp -inline -all $re2 $filedata
} 10000]
set t1 [lindex $t1 0]
set t2 [lindex $t2 0]
puts "t1=$t1, t2=$t2"
# If these two times are within 20% of each other, caching isn't working
expr {$t2 * 1.0 / $t1 < 1.2 && $t1 * 1.0 / $t2 < 1.2}
} {0}
test regexp-1.2 {Non-ascii} {
set nbsp [format %c 0xa0]
set string [format "abc%cdef" 0xa0]
list [regexp "(.*)[set nbsp](.*)" $string dummy f1 f2] $f1 $f2
} {1 abc def}
|