Deutsch   English   Français   Italiano  
<vl0gfm$26irh$1@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: good to know: tcl static "regexp" is faster than tcl "string"
 operation
Date: Tue, 31 Dec 2024 11:19:34 +0100
Organization: A noiseless patient Spider
Lines: 30
Message-ID: <vl0gfm$26irh$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 31 Dec 2024 11:19:34 +0100 (CET)
Injection-Info: dont-email.me; posting-host="87e426919f3f0b5b7d7e11119e850436";
	logging-data="2313073"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+3v8ZFfYHBS7uWVpGYt0S/pFp0b6ZnROQ="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:9rPBbwnlC1665tt4PzpyC+rT+g0=
Content-Language: en-US
Bytes: 1539

#!/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
   }
}

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]


 > ./sbin/time-check.tcl
1=1.26311 microseconds per iteration
2=1.09152 microseconds per iteration
3=1.44028 microseconds per iteration
4=1.43917 microseconds per iteration