Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

Someone is speaking well of you. How unusual!


comp / comp.lang.tcl / Re: good to know: tcl static "regexp" is faster than tcl "string" operation

SubjectAuthor
* good to know: tcl static "regexp" is faster than tcl "string" operationaotto1968
`* Re: good to know: tcl static "regexp" is faster than tcl "string" operationRich
 +- Re: good to know: tcl static "regexp" is faster than tcl "string" operationaotto1968
 `* Re: good to know: tcl static "regexp" is faster than tcl "string" operationaotto1968
  `* Re: good to know: tcl static "regexp" is faster than tcl "string" operationeric
   `- Re: good to know: tcl static "regexp" is faster than tcl "string" operationaotto1968

1
Subject: good to know: tcl static "regexp" is faster than tcl "string" operation
From: aotto1968
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Tue, 31 Dec 2024 10:19 UTC
Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: aotto1968@t-online.de (aotto1968)
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
View all headers

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

Subject: Re: good to know: tcl static "regexp" is faster than tcl "string" operation
From: Rich
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Tue, 31 Dec 2024 13:46 UTC
References: 1
Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: rich@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: good to know: tcl static "regexp" is faster than tcl "string" operation
Date: Tue, 31 Dec 2024 13:46:44 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 72
Message-ID: <vl0sk4$28nvd$1@dont-email.me>
References: <vl0gfm$26irh$1@dont-email.me>
Injection-Date: Tue, 31 Dec 2024 14:46:44 +0100 (CET)
Injection-Info: dont-email.me; posting-host="12c0195d464103dac75cb92dd1eac4a9";
logging-data="2383853"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19phgpBsAmXEb77DDoHOWXu"
User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64))
Cancel-Lock: sha1:7mGbMG0a7ZaVPFuLavgMdhdsClQ=
View all headers

aotto1968 <aotto1968@t-online.de> wrote:
> #!/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

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

Subject: Re: good to know: tcl static "regexp" is faster than tcl "string" operation
From: aotto1968
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Tue, 31 Dec 2024 18:24 UTC
References: 1 2
Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: aotto1968@t-online.de (aotto1968)
Newsgroups: comp.lang.tcl
Subject: Re: good to know: tcl static "regexp" is faster than tcl "string"
operation
Date: Tue, 31 Dec 2024 19:24:30 +0100
Organization: A noiseless patient Spider
Lines: 75
Message-ID: <vl1csu$2bnb8$1@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:24:31 +0100 (CET)
Injection-Info: dont-email.me; posting-host="87e426919f3f0b5b7d7e11119e850436";
logging-data="2481512"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18/wWYSltRbSU2fQJxFHelTifS8AYWFeng="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:UUM5gdFf9mheaWZVJYDdS1qcUx8=
Content-Language: en-US
In-Reply-To: <vl0sk4$28nvd$1@dont-email.me>
View all headers

On 31.12.24 14:46, Rich wrote:
> aotto1968 <aotto1968@t-online.de> wrote:
>> #!/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
>
> 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

→ thanks.

Subject: Re: good to know: tcl static "regexp" is faster than tcl "string" operation
From: aotto1968
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Tue, 31 Dec 2024 18:33 UTC
References: 1 2
Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: aotto1968@t-online.de (aotto1968)
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>
View all headers

....
>
> 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

Subject: Re: good to know: tcl static "regexp" is faster than tcl "string" operation
From: eric
Newsgroups: comp.lang.tcl
Organization: novaBBS
Date: Thu, 2 Jan 2025 11:04 UTC
References: 1 2 3
Path: news.eternal-september.org!eternal-september.org!feeder3.eternal-september.org!i2pn.org!i2pn2.org!.POSTED!not-for-mail
From: eric.boudaillier@gmail.com (eric)
Newsgroups: comp.lang.tcl
Subject: Re: good to know: tcl static "regexp" is faster than tcl "string" operation
Date: Thu, 2 Jan 2025 11:04:50 +0000
Organization: novaBBS
Message-ID: <96487bdefbceb235c3b7bfbf6a358ae9@www.novabbs.com>
References: <vl0gfm$26irh$1@dont-email.me> <vl0sk4$28nvd$1@dont-email.me> <vl1de5$2bnb8$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: i2pn2.org;
logging-data="1636641"; mail-complaints-to="usenet@i2pn2.org";
posting-account="2JEAm3D9ocdCuYwa+m20cOvBPadlxuLgoV1/EdYiPPA";
User-Agent: Rocksolid Light
X-Spam-Checker-Version: SpamAssassin 4.0.0
X-Rslight-Site: $2y$10$zeBeaZx4RE853fT13wjrLOMq22twRevYoyXB81QzkNsfkUFeKM.J2
X-Rslight-Posting-User: 93ec2e00508d433b94505aabe5c8dd9d725b9aa1
View all headers

On Tue, 31 Dec 2024 18:33:41 +0000, aotto1968 wrote:

> ....
> On 31.12.24 14:46, Rich wrote:
>>
>> But neither is quite as fast as string match (athough regex is close):

This kind of regexp generates bytecode using string match instead.
The time difference between both is due to the if-else construct.

tcl::unsupported::disassemble proc test-1
ByteCode 0x0450C010, refCt 1, epoch 18, interp 0x0442C8C0 (epoch 18)
Source "\n if {[regexp ^:: $val]} {\n return true\n } e..."
Cmds 4, src 81, inst 36, litObjs 3, aux 0, stkDepth 2, code/src 0.00
Proc 0x04551488, refCt 1, args 1, compiled locals 1
slot 0, scalar, arg, "val"
Commands 4:
1: pc 0-34, src 4-79 2: pc 0-5, src 9-23
3: pc 9-20, src 34-44 4: pc 23-34, src 63-74
Command 1: "if {[regexp ^:: $val]} {\n return true\n } else
{..."
Command 2: "regexp ^:: $val..."
(0) push1 0 # "::*"
(2) loadScalar1 %v0 # var "val"
(4) strmatch +0
(6) nop
(7) jumpFalse1 +16 # pc 23
Command 3: "return true..."
(9) startCommand +12 1 # next cmd at pc 21, 1 cmds start here
(18) push1 1 # "true"
(20) done
(21) jump1 +14 # pc 35
Command 4: "return false..."
(23) startCommand +12 1 # next cmd at pc 35, 1 cmds start here
(32) push1 2 # "false"
(34) done
(35) done

Eric

--

Subject: Re: good to know: tcl static "regexp" is faster than tcl "string" operation
From: aotto1968
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Thu, 2 Jan 2025 19:23 UTC
References: 1 2 3 4
Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: aotto1968@t-online.de (aotto1968)
Newsgroups: comp.lang.tcl
Subject: Re: good to know: tcl static "regexp" is faster than tcl "string"
operation
Date: Thu, 2 Jan 2025 20:23:45 +0100
Organization: A noiseless patient Spider
Lines: 62
Message-ID: <vl6p43$3fp68$1@dont-email.me>
References: <vl0gfm$26irh$1@dont-email.me> <vl0sk4$28nvd$1@dont-email.me>
<vl1de5$2bnb8$2@dont-email.me>
<96487bdefbceb235c3b7bfbf6a358ae9@www.novabbs.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 02 Jan 2025 20:23:47 +0100 (CET)
Injection-Info: dont-email.me; posting-host="9d3496f00138e55f526a31e5dddeac6d";
logging-data="3663048"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+ozzSrjlMHEhdAMpq04/KgJ2vsY3LC5F0="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:Vdc/Zoq7RaGSEvRalKJdEE1EeTM=
Content-Language: en-US
In-Reply-To: <96487bdefbceb235c3b7bfbf6a358ae9@www.novabbs.com>
View all headers

On 02.01.25 12:04, eric wrote:
> On Tue, 31 Dec 2024 18:33:41 +0000, aotto1968 wrote:
>
>> ....
>> On 31.12.24 14:46, Rich wrote:
>>>
>>> But neither is quite as fast as string match (athough regex is close):
>
>
> This kind of regexp generates bytecode using string match instead.
> The time difference between both is due to the if-else construct.
>
> tcl::unsupported::disassemble proc test-1
> ByteCode 0x0450C010, refCt 1, epoch 18, interp 0x0442C8C0 (epoch 18)
>  Source "\n   if {[regexp ^:: $val]} {\n     return true\n   } e..."
>  Cmds 4, src 81, inst 36, litObjs 3, aux 0, stkDepth 2, code/src 0.00
>  Proc 0x04551488, refCt 1, args 1, compiled locals 1
>      slot 0, scalar, arg, "val"
>  Commands 4:
>      1: pc 0-34, src 4-79        2: pc 0-5, src 9-23
>      3: pc 9-20, src 34-44        4: pc 23-34, src 63-74
>  Command 1: "if {[regexp ^:: $val]} {\n     return true\n   } else
> {..."
>  Command 2: "regexp ^:: $val..."
>    (0) push1 0     # "::*"
>    (2) loadScalar1 %v0     # var "val"
>    (4) strmatch +0
>    (6) nop
>    (7) jumpFalse1 +16     # pc 23
>  Command 3: "return true..."
>    (9) startCommand +12 1     # next cmd at pc 21, 1 cmds start here
>    (18) push1 1     # "true"
>    (20) done
>    (21) jump1 +14     # pc 35
>  Command 4: "return false..."
>    (23) startCommand +12 1     # next cmd at pc 35, 1 cmds start here
>    (32) push1 2     # "false"
>    (34) done
>    (35) done
>
> Eric
>
> --

other stuff

# OLD

proc ::myoo::ClassIs {myR cls} {
upvar $myR my
expr {[llength [lsearch -exact -sorted [set $my(__CLASS__)::__SUPER__SORTED__] $cls]] > 0}
}

# want to have

proc ::myoo::ClassIs {myR cls} {
upvar $myR my
lsearch -exists -exact -sorted [set $my(__CLASS__)::__SUPER__SORTED__] $cls
}

ONE simple FLAG erase a lot of code.

1

rocksolid light 0.9.8
clearnet tor