| Deutsch English Français Italiano |
|
<96487bdefbceb235c3b7bfbf6a358ae9@www.novabbs.com> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!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
Bytes: 2395
Lines: 41
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
--