Menu

[r3]: / lib / CompPerf.CVS / tcl_map.perf  Maximize  Restore  History

Download this file

167 lines (129 with data), 5.6 kB

#§
#§  CompPerf - tcl_map.perf
#§
#§  (C) IPN - Ingenieurbuero fuer Praezisionsnumerik
#§
#§  Dipl.-Ing. Andreas Otto
#§  Ulmenstrasse 3
#§  D-34289 Zierenberg
#§  mailto:aotto@t-online.de
#§
#§  Alle Rechte vorbehalten
#§

package require PerfLib

##
## -----------------------------------------------------
## the test-procs
##

if { [catch {string map {a b} "abc"}] } {
    proc map-str {str nocase args} { return -code 666 "(8.2+)" }
} else {
    proc map-str {str nocase mapChars} {
    if {[string equal [ list -nocase ] $nocase]} {
        return [string map -nocase $mapChars $str]
    } else {
        return [string map $mapChars $str]
    }
    }
}

if {[info tclversion] < 7.5} {
    proc map-regsub {str nocase mapChars} {
    while {$mapChars != ""} {
        set exp [lindex $mapChars 0]
        set subspec [lindex $mapChars 1]
        set mapChars [lrange $mapChars 2 end]
        if {[string equal [ list -nocase ] $nocase]} {
            regsub -all -nocase $exp $str $subspec str
        } else {
            regsub -all $exp $str $subspec str
        }
    }
    return $str
    }
} else {
    proc map-regsub {str nocase mapChars} {
    foreach {exp subspec} $mapChars {
        if {[string equal [ list -nocase ] $nocase]} {
            regsub -all -nocase $exp $str $subspec str
        } else {
            regsub -all $exp $str $subspec str
        }
    }
    return $str
    }
}

proc long-string {} {
    global  longString
    set longString ""
    for {set i 0} {$i < 200} {incr i} {
        append longString "abcdefghijklmnopqrstuvwxyz01234567890123"
    }
}

proc utf-string {} {
    global  ustring
    set ustring ""
    for {set i 0} {$i < 200} {incr i} {
        append ustring "abcdefghijklmnopqrstuvwxyz0123456789012\374"
    }
    append longString 0987654321
}

##
## -----------------------------------------------------
## make the test's
##

set NUM     [ ::PerfLib::Num 40 ]

set TOTAL   [ time {

    ::PerfLib::Register long-string "create a long string"
    ::PerfLib::Run      long-string [time {long-string} $NUM]

    ::PerfLib::Register utf-string "create a utf string"
    ::PerfLib::Run      utf-string [time {utf-string} $NUM]

    ::PerfLib::Register map-strA "MAP string 1 val"
    ::PerfLib::Run      map-strA [time {map-str $longString -- {a at} } $NUM]

    ::PerfLib::Register map-strB "MAP string 2 val"
    ::PerfLib::Run      map-strB [time {map-str $longString -- {a at 0123 0} } $NUM]

    ::PerfLib::Register map-strC "MAP string 3 val"
    ::PerfLib::Run      map-strC [time {map-str $longString -- {a at 0123 0 456 4} } $NUM]

    ::PerfLib::Register map-strD "MAP string 4 val"
    ::PerfLib::Run      map-strD [time {map-str $longString -- {a at 0123 0 456 4 jkl k} } $NUM]

    ::PerfLib::Register map-strE "MAP string 1 val -nocase"
    ::PerfLib::Run      map-strE [time {map-str $longString -nocase {A at} } $NUM]

    ::PerfLib::Register map-strF "MAP string 2 val -nocase"
    ::PerfLib::Run      map-strF [time {map-str $longString -nocase {A at 0123 0} } $NUM]

    ::PerfLib::Register map-strG "MAP string 3 val -nocase"
    ::PerfLib::Run      map-strG [time {map-str $longString -nocase {A at 0123 0 456 4} } $NUM]

    ::PerfLib::Register map-strH "MAP string 4 val -nocase"
    ::PerfLib::Run      map-strH [time {map-str $longString -nocase {A at 0123 0 456 4 jkl k} } $NUM]

    ::PerfLib::Register map-regsubA "MAP regsub 1 val"
    ::PerfLib::Run      map-regsubA [time {map-regsub $longString -- {a at} } $NUM]

    ::PerfLib::Register map-regsubB "MAP regsub 2 val"
    ::PerfLib::Run      map-regsubB [time {map-regsub $longString -- {a at 0123 0} } $NUM]

    ::PerfLib::Register map-regsubC "MAP regsub 3 val"
    ::PerfLib::Run      map-regsubC [time {map-regsub $longString -- {a at 0123 0 456 4} } $NUM]

    ::PerfLib::Register map-regsubD "AP regsub 4 val"
    ::PerfLib::Run      map-regsubD [time {map-regsub $longString -- {a at 0123 0 456 4 jkl k} } $NUM]

    ::PerfLib::Register map-regsubE "MAP regsub 1 val -nocase"
    ::PerfLib::Run      map-regsubE [time {map-regsub $longString -nocase {A at} } $NUM]

    ::PerfLib::Register map-regsubF "MAP regsub 2 val -nocase"
    ::PerfLib::Run      map-regsubF [time {map-regsub $longString -nocase {A at 0123 0} } $NUM]

    ::PerfLib::Register map-regsubG "MAP regsub 3 val -nocase"
    ::PerfLib::Run      map-regsubG [time {map-regsub $longString -nocase {A at 0123 0 456 4} } $NUM]

    ::PerfLib::Register map-regsubH "MAP regsub 4 val -nocase"
    ::PerfLib::Run      map-regsubH [time {map-regsub $longString -nocase {A at 0123 0 456 4 jkl k} } $NUM]

    ::PerfLib::Register map-strI "MAP string, no match"
    ::PerfLib::Run      map-strI [time {map-str $longString -- {=! != qwerty uiop} } $NUM]

    ::PerfLib::Register map-strJ "MAP string -nocase, no match"
    ::PerfLib::Run      map-strJ [time {map-str $longString -nocase {=! != QWERTY uiop} } $NUM]

    ::PerfLib::Register map-regsubI "MAP regsub, no match"
    ::PerfLib::Run      map-regsubI [time {map-regsub $longString -- {=! != qwerty uiop} } $NUM]

    ::PerfLib::Register map-regsubJ "MAP regsub -nocase, no match"
    ::PerfLib::Run      map-regsubJ [time {map-regsub $longString -nocase {=! != QWERTY uiop} } $NUM]

    ::PerfLib::Register map-strK "MAP string short"
    ::PerfLib::Run      map-strK [time {map-str "a b c d e f g h " -- {{ } +} } $NUM]

    ::PerfLib::Register map-regsubK "MAP regsub short"
    ::PerfLib::Run      map-regsubK [time {map-regsub "a b c d e f g h " -- {{ } +} } $NUM]

} 1 ]

##
## -----------------------------------------------------
## cleanup
##

::PerfLib::Exit

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.