Deutsch   English   Français   Italiano  
<vl1de5$2bnb8$2@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: aotto1968 <aotto1968@t-online.de>
Newsgroups: comp.lang.tcl
Subject: Re: good to know: tcl static "regexp" is faster than tcl "string"
 operation
Date: Tue, 31 Dec 2024 19:33:41 +0100
Organization: A noiseless patient Spider
Lines: 68
Message-ID: <vl1de5$2bnb8$2@dont-email.me>
References: <vl0gfm$26irh$1@dont-email.me> <vl0sk4$28nvd$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 31 Dec 2024 19:33:41 +0100 (CET)
Injection-Info: dont-email.me; posting-host="87e426919f3f0b5b7d7e11119e850436";
	logging-data="2481512"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+fArJv+0+t7MGDTtEJ0xS7h49gfOu+rMs="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:tIXn3G+ZpwX/jcyLr+g0TcqonYs=
Content-Language: en-US
In-Reply-To: <vl0sk4$28nvd$1@dont-email.me>
Bytes: 2792

....
> 
> But neither is quite as fast as string match (athough regex is close):
> 
> $ cat time-check.tcl
> #!/usr/bin/env tclsh
> 
> proc test-1 { val } {
>    if {[regexp ^:: $val]} {
>      return true
>    } else {
>      return false
>    }
> }
> 
> proc test-2 { val } {
>    if {[string range $val 0 1] eq "::"} {
>      return true
>    } else {
>      return false
>    }
> }
> 
> proc test-3 { val } {
>    return [string match ::* $val]
> }
> 
> set num 100000
> puts 1=[time {test-1 ::otto} $num]
> puts 2=[time {test-1 otto}   $num]
> puts 3=[time {test-2 ::otto} $num]
> puts 4=[time {test-2 otto}   $num]
> puts 5=[time {test-3 ::otto} $num]
> puts 6=[time {test-3 otto}   $num]
> 
> $ ./time-check.tcl
> 1=0.45252 microseconds per iteration
> 2=0.42354 microseconds per iteration
> 3=0.58949 microseconds per iteration
> 4=0.58363 microseconds per iteration
> 5=0.4351 microseconds per iteration
> 6=0.41378 microseconds per iteration

interesting

1) tcl with debug on

[debug].../NHI1> ./sbin/tcl-time-check.tcl
1=1.07665 microseconds per iteration
2=1.04722 microseconds per iteration
3=1.34974 microseconds per iteration
4=1.34743 microseconds per iteration
5=1.07671 microseconds per iteration
6=1.04552 microseconds per iteration

2) tcl with "production" switch on

[release].../NHI1> ./sbin/tcl-time-check.tcl
1=0.32721 microseconds per iteration
2=0.31452 microseconds per iteration
3=0.4352 microseconds per iteration
4=0.43953 microseconds per iteration
5=0.32741 microseconds per iteration
6=0.31617 microseconds per iteration

there is NO difference between "regexp" and "string match" for

→ Intel(R) Xeon(R) CPU E3-1275 V2 @ 3.50GHz