Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

19 May, 2024: Line wrapping has been changed to be consistent with Usenet standards.
 If you find that it is broken please let me know here rocksolid.nodes.help


devel / comp.lang.tcl / Re: speed improve wanted

SubjectAuthor
* speed improve wantedclt.to.davebr
`* speed improve wantedrola...@gmail.com
 `* speed improve wantedet99
  `* speed improve wantedrola...@gmail.com
   `* speed improve wantedet99
    `- speed improve wantedet99

1
speed improve wanted

<4611682150660@dlp>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=11322&group=comp.lang.tcl#11322

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: clt.to.d...@dfgh.net
Newsgroups: comp.lang.tcl
Subject: speed improve wanted
Date: Sat, 22 Apr 23 08:04:20 GMT
Organization: A noiseless patient Spider
Lines: 12
Message-ID: <4611682150660@dlp>
Injection-Info: dont-email.me; posting-host="d2a760d9b35f4ce2e3cfba2f4a59a1ec";
logging-data="3367546"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/iD4yb7CeLwX235vF5/Fvg"
Cancel-Lock: sha1:ilFnM9qf1zFyr9yWMTCHn4w6ifs=
 by: clt.to.d...@dfgh.net - Sat, 22 Apr 2023 08:04 UTC

You can improve speed in TCL (and probably python as well) by:

stop searching down any column once the position is past the current shortest sequence found.

when a new short sequence is found, save only enough information to generate the result. Only when all columns are searched, do the work to generate the result. Saving copies of even large structures is very fast in TCL (the C code just copies of a pointer, and increments a reference count).

In TCL if the data is organized as a list of sequences (which are lists of 0 and 1) the foreach command can be used to process the list of columns and the list of bits in each column.

I'm seeing about a 10x speed up over the original code by using these suggestions, where both are procedures (to get them compiled).

Dave B

Re: speed improve wanted

<615b693f-476f-4f41-83bb-a98655f23c55n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=11324&group=comp.lang.tcl#11324

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:620a:134d:b0:746:9411:4c18 with SMTP id c13-20020a05620a134d00b0074694114c18mr1590311qkl.5.1682155684316;
Sat, 22 Apr 2023 02:28:04 -0700 (PDT)
X-Received: by 2002:a37:c443:0:b0:74e:3a3c:2da3 with SMTP id
h3-20020a37c443000000b0074e3a3c2da3mr905967qkm.1.1682155684105; Sat, 22 Apr
2023 02:28:04 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border-2.nntp.ord.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Sat, 22 Apr 2023 02:28:03 -0700 (PDT)
In-Reply-To: <4611682150660@dlp>
Injection-Info: google-groups.googlegroups.com; posting-host=116.12.56.93; posting-account=59xCUwoAAABx9tq6XUTZW-wQ1A7Z8t9L
NNTP-Posting-Host: 116.12.56.93
References: <4611682150660@dlp>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <615b693f-476f-4f41-83bb-a98655f23c55n@googlegroups.com>
Subject: Re: speed improve wanted
From: rolan...@gmail.com (rola...@gmail.com)
Injection-Date: Sat, 22 Apr 2023 09:28:04 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 32
 by: rola...@gmail.com - Sat, 22 Apr 2023 09:28 UTC

clt.to...@dfgh.net 在 2023年4月22日 星期六晚上8:04:24 [UTC+12] 的信中寫道:
> You can improve speed in TCL (and probably python as well) by:
>
> stop searching down any column once the position is past the current shortest sequence found.
>
> when a new short sequence is found, save only enough information to generate the result. Only when all columns are searched, do the work to generate the result. Saving copies of even large structures is very fast in TCL (the C code just copies of a pointer, and increments a reference count).
>
> In TCL if the data is organized as a list of sequences (which are lists of 0 and 1) the foreach command can be used to process the list of columns and the list of bits in each column.
>
> I'm seeing about a 10x speed up over the original code by using these suggestions, where both are procedures (to get them compiled).
>
> Dave B

Hi Dave

thanks for your advice , already change the search method ,as you mention get the ideal speed
what I post the topic is search for more help , if the search method no room to improve , how to improve tcl performance ...
different lang have performance gap..
Could you point out my code where to improve with same search method.

BR
Rolance

Re: speed improve wanted

<u212km$3bh8e$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=11326&group=comp.lang.tcl#11326

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: et9...@rocketship1.me (et99)
Newsgroups: comp.lang.tcl
Subject: Re: speed improve wanted
Date: Sat, 22 Apr 2023 09:39:50 -0700
Organization: A noiseless patient Spider
Lines: 60
Message-ID: <u212km$3bh8e$1@dont-email.me>
References: <4611682150660@dlp>
<615b693f-476f-4f41-83bb-a98655f23c55n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 22 Apr 2023 16:39:50 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="784e9a4ce629d41436575249716a459f";
logging-data="3523854"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+6Io/fAI67yFY6iv6TyskU"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.6.1
Cancel-Lock: sha1:ffvv3Y6GNelL3jLSiHbPE/3MHs0=
In-Reply-To: <615b693f-476f-4f41-83bb-a98655f23c55n@googlegroups.com>
Content-Language: en-US
 by: et99 - Sat, 22 Apr 2023 16:39 UTC

On 4/22/2023 2:28 AM, rola...@gmail.com wrote:
> clt.to...@dfgh.net 在 2023年4月22日 星期六晚上8:04:24 [UTC+12] 的信中寫道:
>> You can improve speed in TCL (and probably python as well) by:
>>
>> stop searching down any column once the position is past the current shortest sequence found.
>>
>> when a new short sequence is found, save only enough information to generate the result. Only when all columns are searched, do the work to generate the result. Saving copies of even large structures is very fast in TCL (the C code just copies of a pointer, and increments a reference count).
>>
>> In TCL if the data is organized as a list of sequences (which are lists of 0 and 1) the foreach command can be used to process the list of columns and the list of bits in each column.
>>
>> I'm seeing about a 10x speed up over the original code by using these suggestions, where both are procedures (to get them compiled).
>>
>> Dave B
>
> Hi Dave
>
> thanks for your advice , already change the search method ,as you mention get the ideal speed
> what I post the topic is search for more help , if the search method no room to improve , how to improve tcl performance ...
> different lang have performance gap..
> Could you point out my code where to improve with same search method.
>
> BR
> Rolance

As Dave suggested, using a list of lists is likely the best bet. Then
you could use [lindex $matrix $i $j] for the test, and don't test against
being = to 1, just do a boolean test.

you can see the bytecode with

tcl::unsupported::disassemble proc find_shortest_hit_org

or

tcl::unsupported::disassemble script {if {[lindex $lst 1 1]} {set x 1}}

where one would see (partially shown):
...
Command 1: "if {[lindex $lst 1 1]} {set x 1}"
Command 2: "lindex $lst 1 1..."
(0) push1 0 # "lst"
(2) loadStk
(3) push1 1 # "1"
(5) push1 1 # "1"
(7) lindexMulti 3
(12) nop
(13) jumpFalse1 +9 # pc 22

so there is a specific byte code for an lindex with more than 1 index
and you can use the [time] command to just test small script code, say
to compare an array lookup vs. a list lookup.

Re: speed improve wanted

<5095045c-cb18-48dd-96f4-ab322555c270n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=11328&group=comp.lang.tcl#11328

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:6214:b85:b0:5ef:4390:3d34 with SMTP id fe5-20020a0562140b8500b005ef43903d34mr1654591qvb.1.1682200470542;
Sat, 22 Apr 2023 14:54:30 -0700 (PDT)
X-Received: by 2002:ad4:57c2:0:b0:5e7:95f1:1edc with SMTP id
y2-20020ad457c2000000b005e795f11edcmr1571137qvx.7.1682200470320; Sat, 22 Apr
2023 14:54:30 -0700 (PDT)
Path: i2pn2.org!rocksolid2!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Sat, 22 Apr 2023 14:54:30 -0700 (PDT)
In-Reply-To: <u212km$3bh8e$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=116.12.56.93; posting-account=59xCUwoAAABx9tq6XUTZW-wQ1A7Z8t9L
NNTP-Posting-Host: 116.12.56.93
References: <4611682150660@dlp> <615b693f-476f-4f41-83bb-a98655f23c55n@googlegroups.com>
<u212km$3bh8e$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <5095045c-cb18-48dd-96f4-ab322555c270n@googlegroups.com>
Subject: Re: speed improve wanted
From: rolan...@gmail.com (rola...@gmail.com)
Injection-Date: Sat, 22 Apr 2023 21:54:30 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 3961
 by: rola...@gmail.com - Sat, 22 Apr 2023 21:54 UTC

et99 在 2023年4月23日 星期日凌晨4:39:55 [UTC+12] 的信中寫道:
> On 4/22/2023 2:28 AM, rola...@gmail.com wrote:
> > clt.to...@dfgh.net 在 2023年4月22日 星期六晚上8:04:24 [UTC+12] 的信中寫道:
> >> You can improve speed in TCL (and probably python as well) by:
> >>
> >> stop searching down any column once the position is past the current shortest sequence found.
> >>
> >> when a new short sequence is found, save only enough information to generate the result. Only when all columns are searched, do the work to generate the result. Saving copies of even large structures is very fast in TCL (the C code just copies of a pointer, and increments a reference count).
> >>
> >> In TCL if the data is organized as a list of sequences (which are lists of 0 and 1) the foreach command can be used to process the list of columns and the list of bits in each column.
> >>
> >> I'm seeing about a 10x speed up over the original code by using these suggestions, where both are procedures (to get them compiled).
> >>
> >> Dave B
> >
> > Hi Dave
> >
> > thanks for your advice , already change the search method ,as you mention get the ideal speed
> > what I post the topic is search for more help , if the search method no room to improve , how to improve tcl performance ...
> > different lang have performance gap..
> > Could you point out my code where to improve with same search method.
> >
> > BR
> > Rolance
> As Dave suggested, using a list of lists is likely the best bet. Then
> you could use [lindex $matrix $i $j] for the test, and don't test against
> being = to 1, just do a boolean test.
>
> you can see the bytecode with
>
> tcl::unsupported::disassemble proc find_shortest_hit_org
>
> or
>
> tcl::unsupported::disassemble script {if {[lindex $lst 1 1]} {set x 1}}
>
> where one would see (partially shown):
> ...
> Command 1: "if {[lindex $lst 1 1]} {set x 1}"
> Command 2: "lindex $lst 1 1..."
> (0) push1 0 # "lst"
> (2) loadStk
> (3) push1 1 # "1"
> (5) push1 1 # "1"
> (7) lindexMulti 3
> (12) nop
> (13) jumpFalse1 +9 # pc 22
>
>
> so there is a specific byte code for an lindex with more than 1 index
> and you can use the [time] command to just test small script code, say
> to compare an array lookup vs. a list lookup.

hi et99

thanks your suggestion , will try and report later.

BR
Rolance

Re: speed improve wanted

<u21mov$3f08d$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=11329&group=comp.lang.tcl#11329

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: et9...@rocketship1.me (et99)
Newsgroups: comp.lang.tcl
Subject: Re: speed improve wanted
Date: Sat, 22 Apr 2023 15:23:26 -0700
Organization: A noiseless patient Spider
Lines: 125
Message-ID: <u21mov$3f08d$1@dont-email.me>
References: <4611682150660@dlp>
<615b693f-476f-4f41-83bb-a98655f23c55n@googlegroups.com>
<u212km$3bh8e$1@dont-email.me>
<5095045c-cb18-48dd-96f4-ab322555c270n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 22 Apr 2023 22:23:27 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="bae71f64fc67ab090941b7d690141e44";
logging-data="3637517"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX196JNlHKNijbWcs+gLrzjhh"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.6.1
Cancel-Lock: sha1:fOOHSMY6pQdIDo6UFjO3y13mPnE=
Content-Language: en-US
In-Reply-To: <5095045c-cb18-48dd-96f4-ab322555c270n@googlegroups.com>
 by: et99 - Sat, 22 Apr 2023 22:23 UTC

On 4/22/2023 2:54 PM, rola...@gmail.com wrote:
> et99 在 2023年4月23日 星期日凌晨4:39:55 [UTC+12] 的信中寫道:
>> On 4/22/2023 2:28 AM, rola...@gmail.com wrote:
>>> clt.to...@dfgh.net 在 2023年4月22日 星期六晚上8:04:24 [UTC+12] 的信中寫道:
>>>> You can improve speed in TCL (and probably python as well) by:
>>>>
>>>> stop searching down any column once the position is past the current shortest sequence found.
>>>>
>>>> when a new short sequence is found, save only enough information to generate the result. Only when all columns are searched, do the work to generate the result. Saving copies of even large structures is very fast in TCL (the C code just copies of a pointer, and increments a reference count).
>>>>
>>>> In TCL if the data is organized as a list of sequences (which are lists of 0 and 1) the foreach command can be used to process the list of columns and the list of bits in each column.
>>>>
>>>> I'm seeing about a 10x speed up over the original code by using these suggestions, where both are procedures (to get them compiled).
>>>>
>>>> Dave B
>>>
>>> Hi Dave
>>>
>>> thanks for your advice , already change the search method ,as you mention get the ideal speed
>>> what I post the topic is search for more help , if the search method no room to improve , how to improve tcl performance ...
>>> different lang have performance gap..
>>> Could you point out my code where to improve with same search method.
>>>
>>> BR
>>> Rolance
>> As Dave suggested, using a list of lists is likely the best bet. Then
>> you could use [lindex $matrix $i $j] for the test, and don't test against
>> being = to 1, just do a boolean test.
>>
>> you can see the bytecode with
>>
>> tcl::unsupported::disassemble proc find_shortest_hit_org
>>
>> or
>>
>> tcl::unsupported::disassemble script {if {[lindex $lst 1 1]} {set x 1}}
>>
>> where one would see (partially shown):
>> ...
>> Command 1: "if {[lindex $lst 1 1]} {set x 1}"
>> Command 2: "lindex $lst 1 1..."
>> (0) push1 0 # "lst"
>> (2) loadStk
>> (3) push1 1 # "1"
>> (5) push1 1 # "1"
>> (7) lindexMulti 3
>> (12) nop
>> (13) jumpFalse1 +9 # pc 22
>>
>>
>> so there is a specific byte code for an lindex with more than 1 index
>> and you can use the [time] command to just test small script code, say
>> to compare an array lookup vs. a list lookup.
>
> hi et99
>
> thanks your suggestion , will try and report later.
>
> BR
> Rolance

I did a test using the [lindex $matrix $i $j] and found about a 40% reduction
in time.

It appears that the overhead is beginning to get down to the "if test" and the
"for loop".

This is why Dave is suggesting you use foreach, which has less to do on each
iteration, since the test for the end and incrementing the index is effectively
done in the C code whereas a for loop does that in script code:

% tcl::unsupported::disassemble script {for {set i 1} {$i < $num_rows} {incr i} {doit}}
ByteCode 0x05902750, refCt 1, epoch 17, interp 0x00939060 (epoch 17)
Source "for {set i 1} {$i < $num_rows} {incr i} {doit}"
Cmds 4, src 46, inst 39, litObjs 5, aux 0, stkDepth 2, code/src 0.00
Exception ranges 2, depth 1:
0: level 0, loop, pc 8-11, continue 13, break 36
1: level 0, loop, pc 13-25, continue -1, break 36
Commands 4:
1: pc 0-37, src 0-45 2: pc 0-4, src 5-11
3: pc 8-11, src 41-44 4: pc 13-25, src 32-37
Command 1: "for {set i 1} {$i < $num_rows} {incr i} {doit}"
Command 2: "set i 1..."
(0) push1 0 # "i"
(2) push1 1 # "1"
(4) storeStk
(5) pop
(6) jump1 +21 # pc 27
Command 3: "doit..."
(8) push1 2 # "doit"
(10) invokeStk1 1
(12) pop
Command 4: "incr i..."
(13) startCommand +13 1 # next cmd at pc 26, 1 cmds start here
(22) push1 0 # "i"
(24) incrStkImm +1
(26) pop
(27) push1 0 # "i"
(29) loadStk
(30) push1 3 # "num_rows"
(32) loadStk
(33) lt
(34) jumpTrue1 -26 # pc 8
(36) push1 4 # ""
(38) done

% tcl::unsupported::disassemble script {foreach i $list {doit}}
ByteCode 0x05902650, refCt 1, epoch 17, interp 0x00939060 (epoch 17)
Source "foreach i $list {doit}"
Cmds 1, src 22, inst 12, litObjs 4, aux 0, stkDepth 4, code/src 0.00
Commands 1:
1: pc 0-10, src 0-21
Command 1: "foreach i $list {doit}"
(0) push1 0 # "foreach"
(2) push1 1 # "i"
(4) push1 2 # "list"
(6) loadStk
(7) push1 3 # "doit"
(9) invokeStk1 4
(11) done

Re: speed improve wanted

<u2208j$3ghpk$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=11331&group=comp.lang.tcl#11331

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: et9...@rocketship1.me (et99)
Newsgroups: comp.lang.tcl
Subject: Re: speed improve wanted
Date: Sat, 22 Apr 2023 18:05:22 -0700
Organization: A noiseless patient Spider
Lines: 138
Message-ID: <u2208j$3ghpk$1@dont-email.me>
References: <4611682150660@dlp>
<615b693f-476f-4f41-83bb-a98655f23c55n@googlegroups.com>
<u212km$3bh8e$1@dont-email.me>
<5095045c-cb18-48dd-96f4-ab322555c270n@googlegroups.com>
<u21mov$3f08d$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 23 Apr 2023 01:05:23 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="bae71f64fc67ab090941b7d690141e44";
logging-data="3688244"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/1U19IuZy5+d6cdVU38ITS"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.6.1
Cancel-Lock: sha1:ypnUyGW3mVa3fyi/ZW+j+J/BE1s=
In-Reply-To: <u21mov$3f08d$1@dont-email.me>
Content-Language: en-US
 by: et99 - Sun, 23 Apr 2023 01:05 UTC

On 4/22/2023 3:23 PM, et99 wrote:
> On 4/22/2023 2:54 PM, rola...@gmail.com wrote:
>> et99 在 2023年4月23日 星期日凌晨4:39:55 [UTC+12] 的信中寫道:
>>> On 4/22/2023 2:28 AM, rola...@gmail.com wrote:
>>>> clt.to...@dfgh.net 在 2023年4月22日 星期六晚上8:04:24 [UTC+12] 的信中寫道:
>>>>> You can improve speed in TCL (and probably python as well) by:
>>>>>
>>>>> stop searching down any column once the position is past the current shortest sequence found.
>>>>>
>>>>> when a new short sequence is found, save only enough information to generate the result. Only when all columns are searched, do the work to generate the result. Saving copies of even large structures is very fast in TCL (the C code just copies of a pointer, and increments a reference count).
>>>>>
>>>>> In TCL if the data is organized as a list of sequences (which are lists of 0 and 1) the foreach command can be used to process the list of columns and the list of bits in each column.
>>>>>
>>>>> I'm seeing about a 10x speed up over the original code by using these suggestions, where both are procedures (to get them compiled).
>>>>>
>>>>> Dave B
>>>>
>>>> Hi Dave
>>>>
>>>> thanks for your advice , already change the search method ,as you mention get the ideal speed
>>>> what I post the topic is search for more help , if the search method no room to improve , how to improve tcl performance ...
>>>> different lang have performance gap..
>>>> Could you point out my code where to improve with same search method.
>>>>
>>>> BR
>>>> Rolance
>>> As Dave suggested, using a list of lists is likely the best bet. Then
>>> you could use [lindex $matrix $i $j] for the test, and don't test against
>>> being = to 1, just do a boolean test.
>>>
>>> you can see the bytecode with
>>>
>>> tcl::unsupported::disassemble proc find_shortest_hit_org
>>>
>>> or
>>>
>>> tcl::unsupported::disassemble script {if {[lindex $lst 1 1]} {set x 1}}
>>>
>>> where one would see (partially shown):
>>> ...
>>> Command 1: "if {[lindex $lst 1 1]} {set x 1}"
>>> Command 2: "lindex $lst 1 1..."
>>> (0) push1 0 # "lst"
>>> (2) loadStk
>>> (3) push1 1 # "1"
>>> (5) push1 1 # "1"
>>> (7) lindexMulti 3
>>> (12) nop
>>> (13) jumpFalse1 +9 # pc 22
>>>
>>>
>>> so there is a specific byte code for an lindex with more than 1 index
>>> and you can use the [time] command to just test small script code, say
>>> to compare an array lookup vs. a list lookup.
>>
>> hi et99
>>
>> thanks your suggestion , will try and report later.
>>
>> BR
>> Rolance
>
>
> I did a test using the [lindex $matrix $i $j] and found about a 40% reduction
> in time.
>
> It appears that the overhead is beginning to get down to the "if test" and the
> "for loop".
>
> This is why Dave is suggesting you use foreach, which has less to do on each
> iteration, since the test for the end and incrementing the index is effectively
> done in the C code whereas a for loop does that in script code:
>
>
>
> % tcl::unsupported::disassemble script {for {set i 1} {$i < $num_rows} {incr i} {doit}}
> ByteCode 0x05902750, refCt 1, epoch 17, interp 0x00939060 (epoch 17)
>   Source "for {set i 1} {$i < $num_rows} {incr i} {doit}"
>   Cmds 4, src 46, inst 39, litObjs 5, aux 0, stkDepth 2, code/src 0.00
>   Exception ranges 2, depth 1:
>       0: level 0, loop, pc 8-11, continue 13, break 36
>       1: level 0, loop, pc 13-25, continue -1, break 36
>   Commands 4:
>       1: pc 0-37, src 0-45        2: pc 0-4, src 5-11
>       3: pc 8-11, src 41-44        4: pc 13-25, src 32-37
>   Command 1: "for {set i 1} {$i < $num_rows} {incr i} {doit}"
>   Command 2: "set i 1..."
>     (0) push1 0     # "i"
>     (2) push1 1     # "1"
>     (4) storeStk
>     (5) pop
>     (6) jump1 +21     # pc 27
>   Command 3: "doit..."
>     (8) push1 2     # "doit"
>     (10) invokeStk1 1
>     (12) pop
>   Command 4: "incr i..."
>     (13) startCommand +13 1     # next cmd at pc 26, 1 cmds start here
>     (22) push1 0     # "i"
>     (24) incrStkImm +1
>     (26) pop
>     (27) push1 0     # "i"
>     (29) loadStk
>     (30) push1 3     # "num_rows"
>     (32) loadStk
>     (33) lt
>     (34) jumpTrue1 -26     # pc 8
>     (36) push1 4     # ""
>     (38) done
>
> % tcl::unsupported::disassemble script {foreach i $list {doit}}
> ByteCode 0x05902650, refCt 1, epoch 17, interp 0x00939060 (epoch 17)
>   Source "foreach i $list {doit}"
>   Cmds 1, src 22, inst 12, litObjs 4, aux 0, stkDepth 4, code/src 0.00
>   Commands 1:
>       1: pc 0-10, src 0-21
>   Command 1: "foreach i $list {doit}"
>     (0) push1 0     # "foreach"
>     (2) push1 1     # "i"
>     (4) push1 2     # "list"
>     (6) loadStk
>     (7) push1 3     # "doit"
>     (9) invokeStk1 4
>     (11) done
>
>

On last thought on using foreach, the index is the item itself, 0 or 1, and so
the if test doesn't have to do an array or lindex list lookup.
Something like this:

foreach row {list of the rows}
foreach column $row
if {$column} ....

Actually, I couldn't really tell if you searching a row or a column,
so adjust as needed.


devel / comp.lang.tcl / Re: speed improve wanted

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor