File: string.bench

package info (click to toggle)
tcllib 1.20%2Bdfsg-1
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 68,064 kB
  • sloc: tcl: 216,842; ansic: 14,250; sh: 2,846; xml: 1,766; yacc: 1,145; pascal: 881; makefile: 107; perl: 84; f90: 84; python: 33; ruby: 13; php: 11
file content (116 lines) | stat: -rw-r--r-- 2,809 bytes parent folder | download | duplicates (7)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# -*- tcl -*-
# Tcl Benchmark File
#
# This file contains a number of benchmarks for the 'textutil::string' 
# module. This allow developers to monitor/gauge/track package 
# performance.
#
# (c) 2008 Michael Schlenker <mic42@sourceforge.net>

# We need at least version 8.2 for the package and thus the
# benchmarks.

if {![package vsatisfies [package provide Tcl] 8.2]} {
    return
}

# ### ### ### ######### ######### ######### ###########################
## Setting up the environment ...

package forget log
catch {namespace delete ::log}
source [file join [file dirname [file dirname [info script]]] log log.tcl]

package forget textutil::string
catch {namespace delete ::textutil}
source [file join [file dirname [info script]] string.tcl]

# ### ### ### ######### ######### ######### ###########################
## Benchmarks.

foreach n {1 10 100 1000 5000} {
bench -desc "longestCommonPrefixList - $n char match - 2 elements list" -pre {
    set list [list [string repeat a $n]b [string repeat a $n]c]
} -body {
    set prefix [::textutil::string::longestCommonPrefixList $list]
} -post {
    unset list
    unset prefix
}
}

foreach n {1 10 100 1000 5000} {
bench -desc "longestCommonPrefixList - 10 char match - $n elements list" -pre {
    set elem [string repeat a 10]
    for {set i 0} {$i < $n} {incr i} {
	lappend list "$elem$i"
    }
} -body {
    set prefix [::textutil::string::longestCommonPrefixList $list]
} -post {
    unset list
    unset prefix
}
}

foreach n {1 10 100 1000 5000} {
bench -desc "longestCommonPrefixList - no match - $n elements list" -pre {
    set elem [string repeat a 10]
    for {set i 0} {$i < $n} {incr i} {
	lappend list "$elem$i"
    }
    lappend list "NOPREFIX"
} -body {
    set prefix [::textutil::string::longestCommonPrefixList $list]
} -post {
    unset list
    unset prefix
}
}

foreach n {1 10 100 1000 5000} {
bench -desc "chop one char from $n char string" -pre {
    set str [string repeat a $n]
} -body {
    set chopped [::textutil::string::chop $str]
} -post {
    unset str
    unset chopped 
}
}

foreach n {1 10 100 1000 5000} {
bench -desc "tail one char from $n char string" -pre {
    set str [string repeat a $n]
} -body {
    set tailed [::textutil::string::tail $str]
} -post {
    unset str
    unset tailed
}
}

foreach n {1 10 100 1000 5000} {
bench -desc "cap from $n char string" -pre {
    set str [string repeat a $n]
} -body {
    set capped [::textutil::string::cap $str]
} -post {
    unset str
    unset capped
}
}

foreach n {1 10 100 1000 5000} {
bench -desc "uncap from $n char string" -pre {
    set str [string repeat a $n]
} -body {
    set uncapped [::textutil::string::uncap $str]
} -post {
    unset str
    unset uncapped
}
}

# ### ### ### ######### ######### ######### ###########################
## Complete