Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"If Diet Coke did not exist it would have been necessary to invent it." -- Karl Lehenbauer


devel / comp.lang.tcl / faster Lsearch speed wanted

SubjectAuthor
* faster Lsearch speed wantedrola...@gmail.com
+* faster Lsearch speed wantedheinrichmartin
|`* faster Lsearch speed wantedrola...@gmail.com
| `* faster Lsearch speed wantedheinrichmartin
|  `* faster Lsearch speed wantedheinrichmartin
|   +- faster Lsearch speed wantedrola...@gmail.com
|   +- faster Lsearch speed wantedrola...@gmail.com
|   `* faster Lsearch speed wantedrola...@gmail.com
|    `* faster Lsearch speed wantedRalf Fassel
|     +* faster Lsearch speed wantedrola...@gmail.com
|     |+* faster Lsearch speed wantedheinrichmartin
|     ||`- faster Lsearch speed wantedrola...@gmail.com
|     |`- faster Lsearch speed wantedRich
|     `- faster Lsearch speed wantedRich
`* faster Lsearch speed wantedRich
 +- faster Lsearch speed wantedrola...@gmail.com
 `* faster Lsearch speed wantedrola...@gmail.com
  `* faster Lsearch speed wantedRich
   `* faster Lsearch speed wantedrola...@gmail.com
    `* faster Lsearch speed wantedRich
     `* faster Lsearch speed wantedrola...@gmail.com
      `* faster Lsearch speed wantedrola...@gmail.com
       `* faster Lsearch speed wantedRich
        `* faster Lsearch speed wantedrola...@gmail.com
         `* faster Lsearch speed wantedRich
          `* faster Lsearch speed wantedrola...@gmail.com
           `* faster Lsearch speed wantedRich
            `* faster Lsearch speed wantedrola...@gmail.com
             `* faster Lsearch speed wantedheinrichmartin
              `* faster Lsearch speed wantedrola...@gmail.com
               `* faster Lsearch speed wantedheinrichmartin
                `* faster Lsearch speed wantedrola...@gmail.com
                 `- faster Lsearch speed wantedheinrichmartin

Pages:12
faster Lsearch speed wanted

<15759bdf-5b81-4996-a51b-d8105117ba29n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:620a:191c:b0:6ed:88c5:e839 with SMTP id bj28-20020a05620a191c00b006ed88c5e839mr21457585qkb.627.1667464108627;
Thu, 03 Nov 2022 01:28:28 -0700 (PDT)
X-Received: by 2002:ad4:5def:0:b0:4bb:ae2f:40ac with SMTP id
jn15-20020ad45def000000b004bbae2f40acmr25720697qvb.128.1667464108470; Thu, 03
Nov 2022 01:28:28 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.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: Thu, 3 Nov 2022 01:28:28 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=103.77.4.199; posting-account=59xCUwoAAABx9tq6XUTZW-wQ1A7Z8t9L
NNTP-Posting-Host: 103.77.4.199
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <15759bdf-5b81-4996-a51b-d8105117ba29n@googlegroups.com>
Subject: faster Lsearch speed wanted
From: rolan...@gmail.com (rola...@gmail.com)
Injection-Date: Thu, 03 Nov 2022 08:28:28 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2345
 by: rola...@gmail.com - Thu, 3 Nov 2022 08:28 UTC

Hi all

mass numbers analysis , need improve speed ...

hope someone can give me some hint ,or other way search ....

code list below

set lst [lmap v [lrepeat 3125 1] {set v [expr int($v * [::tcl::mathfunc::rand]*39)]} ]

##### each number +id %39
proc adv_chg_no_range4 {id lst} {
set new_lst [lindex $lst 0]
for {set i 1} {$i < [llength $lst]} {incr i} {
set tmp_val [expr {([lindex $lst $i] + $id -1) % 39} ]
if {$tmp_val == 0} {set tmp_val 39}
lappend new_lst $tmp_val
}
return $new_lst
}

puts [time {

foreach x {1 12 18 5 6} {
lsearch -all -exact $lst $x
}

}

]

puts "###combine ##"

puts [time {

foreach x {1 12 18 5 6} {
lsearch -all [adv_chg_no_range4 1 $lst] $x
}

}

]\n

puts "#### regexp"
puts [time {lsearch -all -regexp $lst (^1$|^12$|^18$|^5$|^6$)}]
puts "###combine ##"
puts [time {lsearch -all -regexp [adv_chg_no_range4 1 $lst] (^1$|^12$|^18$|^5$|^6$)}

output:

328 microseconds per iteration
###combine ##
4928 microseconds per iteration

#### regexp
1341 microseconds per iteration
###combine ##
2525 microseconds per iteration

as the output use single proc -regexp less perfomance ....
but combine with other proc seem better .. Why....

could someone give me direction to overcome speed issue

thanks
Rolance

Re: faster Lsearch speed wanted

<b732b878-55b4-441a-948d-1ce93290f4a1n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:620a:28ce:b0:6cf:933c:40d3 with SMTP id l14-20020a05620a28ce00b006cf933c40d3mr20642478qkp.258.1667471100892;
Thu, 03 Nov 2022 03:25:00 -0700 (PDT)
X-Received: by 2002:ae9:e103:0:b0:6fa:581d:181 with SMTP id
g3-20020ae9e103000000b006fa581d0181mr6615428qkm.695.1667471100751; Thu, 03
Nov 2022 03:25:00 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.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: Thu, 3 Nov 2022 03:25:00 -0700 (PDT)
In-Reply-To: <15759bdf-5b81-4996-a51b-d8105117ba29n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=91.217.55.78; posting-account=Od2xOAoAAACEyRX3Iu5rYt4oevuoeYUG
NNTP-Posting-Host: 91.217.55.78
References: <15759bdf-5b81-4996-a51b-d8105117ba29n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <b732b878-55b4-441a-948d-1ce93290f4a1n@googlegroups.com>
Subject: Re: faster Lsearch speed wanted
From: martin.h...@frequentis.com (heinrichmartin)
Injection-Date: Thu, 03 Nov 2022 10:25:00 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 4625
 by: heinrichmartin - Thu, 3 Nov 2022 10:25 UTC

On Thursday, November 3, 2022 at 9:28:30 AM UTC+1, Rolance wrote:
> Hi all
>
> mass numbers analysis , need improve speed ...
>
> hope someone can give me some hint ,or other way search ....

Are you looking for the fastest code to solve a problem or for a better understanding of the observed timing.
If it is the first, then please also state the actual problem.

Anyway, here are a few comments (hopefully correct, but most likely not covering all aspects).

> set lst [lmap v [lrepeat 3125 1] {set v [expr int($v * [::tcl::mathfunc::rand]*39)]} ]

* $v is always 1 and that factor can be removed from expr.
* The argument to expr should be braced.
* "set v" is unnecessary; {expr {int([::tcl::mathfunc::rand]*39)}} will do.
* You could try whether a simple for-loop is faster than lrepeat+lmap. Tcl increases the internal list size progressively.

> ##### each number +id %39
> proc adv_chg_no_range4 {id lst} {

I guess there is a reason for a proc, i.e. why are you not creating these values straight away.

> set new_lst [lindex $lst 0]

The comment says "each number", but you are not processing the first one.

> for {set i 1} {$i < [llength $lst]} {incr i} {

You seem to know about lmap, why not here?

> set tmp_val [expr {([lindex $lst $i] + $id -1) % 39} ]

You could [incr id -1] once in advance (inside the proc before the loop).

> if {$tmp_val == 0} {set tmp_val 39}

You could time whether [expr {(($v+$id)%-39)+39}] is faster to obtain the range 1~39.

Or the other way round, perform $id%39 in advance and do a conditional range shift in the loop, i.e.
if {$tmp_val > 39} {incr tmp_val -39} {set tmp_val} ;# assuming lmap

Please cross-check correctness on your own, i.e. do not blindly trust me who does not know your actual problem statement.

> puts [time {
>
> foreach x {1 12 18 5 6} {
> lsearch -all -exact $lst $x

Should that be -integer instead of -exact?
Internally, you are creating string reps of the list items here.

> puts "###combine ##"
>
> puts [time {
>
> foreach x {1 12 18 5 6} {
> lsearch -all [adv_chg_no_range4 1 $lst] $x

Is there a reason for calling the proc in every loop?

> puts "#### regexp"
> puts [time {lsearch -all -regexp $lst (^1$|^12$|^18$|^5$|^6$)}]
> puts "###combine ##"
> puts [time {lsearch -all -regexp [adv_chg_no_range4 1 $lst] (^1$|^12$|^18$|^5$|^6$)}

Here, you definitely have a single call to the proc.

>
>
> output:
>
> 328 microseconds per iteration
> ###combine ##
> 4928 microseconds per iteration

This could include compile time of the proc. Do the timing more than once (or call the proc once in advance).

> #### regexp
> 1341 microseconds per iteration
> ###combine ##
> 2525 microseconds per iteration
>
>
> as the output use single proc -regexp less perfomance ....

Exact string comparison is way faster. Even glob-matching is faster, e.g. Expect creates glob-gatekeepers for regexp-matching.
You could try whether {^(?:x1|x2|...)$} matches faster (i.e. if the state-machine is simpler), but in the end the above statement will stand.

> but combine with other proc seem better .. Why....
> could someone give me direction to overcome speed issue

Double the time for 5 times the calls to the proc seems to proof different. You will find out in a cross-check.
In the end, most of my comments turn out to be irrelevant for that final finding ... Maybe they help anyway.

Re: faster Lsearch speed wanted

<379b802a-6ecb-412b-967e-93d51a78545en@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a0c:cb01:0:b0:4be:e9f3:6d0 with SMTP id o1-20020a0ccb01000000b004bee9f306d0mr1053388qvk.3.1667473535398;
Thu, 03 Nov 2022 04:05:35 -0700 (PDT)
X-Received: by 2002:a05:622a:1ba5:b0:3a4:ffd9:22d8 with SMTP id
bp37-20020a05622a1ba500b003a4ffd922d8mr23881925qtb.356.1667473535185; Thu, 03
Nov 2022 04:05:35 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.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: Thu, 3 Nov 2022 04:05:34 -0700 (PDT)
In-Reply-To: <b732b878-55b4-441a-948d-1ce93290f4a1n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=103.77.4.199; posting-account=59xCUwoAAABx9tq6XUTZW-wQ1A7Z8t9L
NNTP-Posting-Host: 103.77.4.199
References: <15759bdf-5b81-4996-a51b-d8105117ba29n@googlegroups.com> <b732b878-55b4-441a-948d-1ce93290f4a1n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <379b802a-6ecb-412b-967e-93d51a78545en@googlegroups.com>
Subject: Re: faster Lsearch speed wanted
From: rolan...@gmail.com (rola...@gmail.com)
Injection-Date: Thu, 03 Nov 2022 11:05:35 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 6109
 by: rola...@gmail.com - Thu, 3 Nov 2022 11:05 UTC

heinrichmartin 在 2022年11月3日 星期四晚上11:25:02 [UTC+13] 的信中寫道:
> On Thursday, November 3, 2022 at 9:28:30 AM UTC+1, Rolance wrote:
> > Hi all
> >
> > mass numbers analysis , need improve speed ...
> >
> > hope someone can give me some hint ,or other way search ....
> Are you looking for the fastest code to solve a problem or for a better understanding of the observed timing.
> If it is the first, then please also state the actual problem.
>
> Anyway, here are a few comments (hopefully correct, but most likely not covering all aspects).
> > set lst [lmap v [lrepeat 3125 1] {set v [expr int($v * [::tcl::mathfunc::rand]*39)]} ]
> * $v is always 1 and that factor can be removed from expr.
> * The argument to expr should be braced.
> * "set v" is unnecessary; {expr {int([::tcl::mathfunc::rand]*39)}} will do.
> * You could try whether a simple for-loop is faster than lrepeat+lmap. Tcl increases the internal list size progressively.
> > ##### each number +id %39
> > proc adv_chg_no_range4 {id lst} {
> I guess there is a reason for a proc, i.e. why are you not creating these values straight away.
> > set new_lst [lindex $lst 0]
> The comment says "each number", but you are not processing the first one.
> > for {set i 1} {$i < [llength $lst]} {incr i} {
> You seem to know about lmap, why not here?
> > set tmp_val [expr {([lindex $lst $i] + $id -1) % 39} ]
> You could [incr id -1] once in advance (inside the proc before the loop).
> > if {$tmp_val == 0} {set tmp_val 39}
> You could time whether [expr {(($v+$id)%-39)+39}] is faster to obtain the range 1~39.
>
> Or the other way round, perform $id%39 in advance and do a conditional range shift in the loop, i.e.
> if {$tmp_val > 39} {incr tmp_val -39} {set tmp_val} ;# assuming lmap
>
> Please cross-check correctness on your own, i.e. do not blindly trust me who does not know your actual problem statement.
> > puts [time {
> >
> > foreach x {1 12 18 5 6} {
> > lsearch -all -exact $lst $x
> Should that be -integer instead of -exact?
> Internally, you are creating string reps of the list items here.
> > puts "###combine ##"
> >
> > puts [time {
> >
> > foreach x {1 12 18 5 6} {
> > lsearch -all [adv_chg_no_range4 1 $lst] $x
> Is there a reason for calling the proc in every loop?
> > puts "#### regexp"
> > puts [time {lsearch -all -regexp $lst (^1$|^12$|^18$|^5$|^6$)}]
> > puts "###combine ##"
> > puts [time {lsearch -all -regexp [adv_chg_no_range4 1 $lst] (^1$|^12$|^18$|^5$|^6$)}
> Here, you definitely have a single call to the proc.
> >
> >
> > output:
> >
> > 328 microseconds per iteration
> > ###combine ##
> > 4928 microseconds per iteration
> This could include compile time of the proc. Do the timing more than once (or call the proc once in advance).
> > #### regexp
> > 1341 microseconds per iteration
> > ###combine ##
> > 2525 microseconds per iteration
> >
> >
> > as the output use single proc -regexp less perfomance ....
> Exact string comparison is way faster. Even glob-matching is faster, e.g. Expect creates glob-gatekeepers for regexp-matching.
> You could try whether {^(?:x1|x2|...)$} matches faster (i.e. if the state-machine is simpler), but in the end the above statement will stand.
> > but combine with other proc seem better .. Why....
> > could someone give me direction to overcome speed issue
> Double the time for 5 times the calls to the proc seems to proof different. You will find out in a cross-check.
> In the end, most of my comments turn out to be irrelevant for that final finding ... Maybe they help anyway.

hi heinrichmartin

thanks for your advice

1. looking for the fastest code to mass data , speed issue need cut down consume time as least half..
this code is part of project , the most affect effience part -- > lsearch command
already try serveal way to get best search time .....
or you have other best way to achieve like dict .. or array search code for reference?

2. (a).why use --> foreach x {1 12 18 5 6} {
lsearch -all -exact $lst $x
(b) not ---> Should that be -integer instead of -exact?

(a): 351 microseconds per iteration <<<<
(b): 583 microseconds per iteration

3. single proc Vs combine proc the time consume not proportional .....
still try to find out which affect momory occupy , not the simply code can get the best perforamce ...
5times faster than one line (-regexp ) code ....

thanks
Rolance

Re: faster Lsearch speed wanted

<a7a61b1c-c881-4d43-b6c4-b2c9bcb00be0n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a37:9246:0:b0:6fa:6e0c:e12 with SMTP id u67-20020a379246000000b006fa6e0c0e12mr4289168qkd.92.1667475711817;
Thu, 03 Nov 2022 04:41:51 -0700 (PDT)
X-Received: by 2002:ac8:5804:0:b0:39c:d63c:95b7 with SMTP id
g4-20020ac85804000000b0039cd63c95b7mr23541314qtg.216.1667475711636; Thu, 03
Nov 2022 04:41:51 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.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: Thu, 3 Nov 2022 04:41:51 -0700 (PDT)
In-Reply-To: <379b802a-6ecb-412b-967e-93d51a78545en@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=91.217.55.78; posting-account=Od2xOAoAAACEyRX3Iu5rYt4oevuoeYUG
NNTP-Posting-Host: 91.217.55.78
References: <15759bdf-5b81-4996-a51b-d8105117ba29n@googlegroups.com>
<b732b878-55b4-441a-948d-1ce93290f4a1n@googlegroups.com> <379b802a-6ecb-412b-967e-93d51a78545en@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <a7a61b1c-c881-4d43-b6c4-b2c9bcb00be0n@googlegroups.com>
Subject: Re: faster Lsearch speed wanted
From: martin.h...@frequentis.com (heinrichmartin)
Injection-Date: Thu, 03 Nov 2022 11:41:51 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 7177
 by: heinrichmartin - Thu, 3 Nov 2022 11:41 UTC

On Thursday, November 3, 2022 at 12:05:37 PM UTC+1, Rolance wrote:
> heinrichmartin 在 2022年11月3日 星期四晚上11:25:02 [UTC+13] 的信中寫道:
> > On Thursday, November 3, 2022 at 9:28:30 AM UTC+1, Rolance wrote:
> > > Hi all
> > >
> > > mass numbers analysis , need improve speed ...
> > >
> > > hope someone can give me some hint ,or other way search ....
> > Are you looking for the fastest code to solve a problem or for a better understanding of the observed timing.
> > If it is the first, then please also state the actual problem.
> >
> > Anyway, here are a few comments (hopefully correct, but most likely not covering all aspects).
> > > set lst [lmap v [lrepeat 3125 1] {set v [expr int($v * [::tcl::mathfunc::rand]*39)]} ]
> > * $v is always 1 and that factor can be removed from expr.
> > * The argument to expr should be braced.
> > * "set v" is unnecessary; {expr {int([::tcl::mathfunc::rand]*39)}} will do.
> > * You could try whether a simple for-loop is faster than lrepeat+lmap. Tcl increases the internal list size progressively.
> > > ##### each number +id %39
> > > proc adv_chg_no_range4 {id lst} {
> > I guess there is a reason for a proc, i.e. why are you not creating these values straight away.
> > > set new_lst [lindex $lst 0]
> > The comment says "each number", but you are not processing the first one.
> > > for {set i 1} {$i < [llength $lst]} {incr i} {
> > You seem to know about lmap, why not here?
> > > set tmp_val [expr {([lindex $lst $i] + $id -1) % 39} ]
> > You could [incr id -1] once in advance (inside the proc before the loop).
> > > if {$tmp_val == 0} {set tmp_val 39}
> > You could time whether [expr {(($v+$id)%-39)+39}] is faster to obtain the range 1~39.
> >
> > Or the other way round, perform $id%39 in advance and do a conditional range shift in the loop, i.e.
> > if {$tmp_val > 39} {incr tmp_val -39} {set tmp_val} ;# assuming lmap
> >
> > Please cross-check correctness on your own, i.e. do not blindly trust me who does not know your actual problem statement.
> > > puts [time {
> > >
> > > foreach x {1 12 18 5 6} {
> > > lsearch -all -exact $lst $x
> > Should that be -integer instead of -exact?
> > Internally, you are creating string reps of the list items here.
> > > puts "###combine ##"
> > >
> > > puts [time {
> > >
> > > foreach x {1 12 18 5 6} {
> > > lsearch -all [adv_chg_no_range4 1 $lst] $x
> > Is there a reason for calling the proc in every loop?
> > > puts "#### regexp"
> > > puts [time {lsearch -all -regexp $lst (^1$|^12$|^18$|^5$|^6$)}]
> > > puts "###combine ##"
> > > puts [time {lsearch -all -regexp [adv_chg_no_range4 1 $lst] (^1$|^12$|^18$|^5$|^6$)}
> > Here, you definitely have a single call to the proc.
> > >
> > >
> > > output:
> > >
> > > 328 microseconds per iteration
> > > ###combine ##
> > > 4928 microseconds per iteration
> > This could include compile time of the proc. Do the timing more than once (or call the proc once in advance).
> > > #### regexp
> > > 1341 microseconds per iteration
> > > ###combine ##
> > > 2525 microseconds per iteration
> > >
> > >
> > > as the output use single proc -regexp less perfomance ....
> > Exact string comparison is way faster. Even glob-matching is faster, e.g. Expect creates glob-gatekeepers for regexp-matching.
> > You could try whether {^(?:x1|x2|...)$} matches faster (i.e. if the state-machine is simpler), but in the end the above statement will stand.
> > > but combine with other proc seem better .. Why....
> > > could someone give me direction to overcome speed issue
> > Double the time for 5 times the calls to the proc seems to proof different. You will find out in a cross-check.
> > In the end, most of my comments turn out to be irrelevant for that final finding ... Maybe they help anyway.
> hi heinrichmartin
>
> thanks for your advice

Not replying inline makes it hard for me to set your points in context.
> 1. looking for the fastest code to mass data , speed issue need cut down consume time as least half..
> this code is part of project , the most affect effience part -- > lsearch command
> already try serveal way to get best search time .....
> or you have other best way to achieve like dict .. or array search code for reference?

lsearch requires O(N) unless you can sort the list in advance WLOG. Dict and array (when using the data as keys) make the values unique; if that was acceptable, then why are you using -all? Besides, lsearch -integer should be unbeatable.

> 2. (a).why use --> foreach x {1 12 18 5 6} {
> lsearch -all -exact $lst $x
> (b) not ---> Should that be -integer instead of -exact?
>
> (a): 351 microseconds per iteration <<<<
> (b): 583 microseconds per iteration

My bad, -integer requires -exact (or -sorted) to take effect and that is not implied. (We had that here on clt; it is counter-intuitive.)

> 3. single proc Vs combine proc the time consume not proportional ....
> still try to find out which affect momory occupy , not the simply code can get the best perforamce ...
> 5times faster than one line (-regexp ) code ....

Let me comment with a quote:

On Thursday, August 13, 2020 at 9:07:54 AM UTC+2, Arjen wrote:
> [...] I do know that such benchmarks are notoriously difficult to get right. [...]

And you seem to have missed many very basic hints about possible improvements wrt Tcl/coding/algorithms in my previous answer ...

Re: faster Lsearch speed wanted

<45115fc7-f397-4b8b-8437-9cf324263085n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:620a:430a:b0:6f6:589b:463d with SMTP id u10-20020a05620a430a00b006f6589b463dmr20960038qko.139.1667476171547;
Thu, 03 Nov 2022 04:49:31 -0700 (PDT)
X-Received: by 2002:a05:620a:15cc:b0:6fa:398d:7cef with SMTP id
o12-20020a05620a15cc00b006fa398d7cefmr14163643qkm.71.1667476171423; Thu, 03
Nov 2022 04:49:31 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.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: Thu, 3 Nov 2022 04:49:31 -0700 (PDT)
In-Reply-To: <a7a61b1c-c881-4d43-b6c4-b2c9bcb00be0n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=91.217.55.78; posting-account=Od2xOAoAAACEyRX3Iu5rYt4oevuoeYUG
NNTP-Posting-Host: 91.217.55.78
References: <15759bdf-5b81-4996-a51b-d8105117ba29n@googlegroups.com>
<b732b878-55b4-441a-948d-1ce93290f4a1n@googlegroups.com> <379b802a-6ecb-412b-967e-93d51a78545en@googlegroups.com>
<a7a61b1c-c881-4d43-b6c4-b2c9bcb00be0n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <45115fc7-f397-4b8b-8437-9cf324263085n@googlegroups.com>
Subject: Re: faster Lsearch speed wanted
From: martin.h...@frequentis.com (heinrichmartin)
Injection-Date: Thu, 03 Nov 2022 11:49:31 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 3136
 by: heinrichmartin - Thu, 3 Nov 2022 11:49 UTC

On Thursday, November 3, 2022 at 12:41:53 PM UTC+1, heinrichmartin wrote:
> On Thursday, November 3, 2022 at 12:05:37 PM UTC+1, Rolance wrote:
> > 3. single proc Vs combine proc the time consume not proportional ....
> > still try to find out which affect momory occupy , not the simply code can get the best perforamce ...
> > 5times faster than one line (-regexp ) code ....
> Let me comment with a quote:
>
> On Thursday, August 13, 2020 at 9:07:54 AM UTC+2, Arjen wrote:
> > [...] I do know that such benchmarks are notoriously difficult to get right. [...]

Btw, here is my quick take on it (including a few cross-checks):
expect:~$ set l [lmap x [lrepeat 10000 1] {expr {int(rand()*39)}}]; puts foo
foo
expect:~$ ll $l
10000
expect:~$ lindex $l 25
22
expect:~$ ::tcl::mathfunc::max {*}$l
38
expect:~$ time {lsearch -all -integer $l [expr {int(rand()*39)}]} 1000
230.131 microseconds per iteration
expect:~$ time {lsearch -all -exact $l [expr {int(rand()*39)}]} 1000
193.889 microseconds per iteration
expect:~$ time {lsearch -all -integer $l [expr {int(rand()*39)}]} 1000
230.803 microseconds per iteration
expect:~$ time {lsearch -all -exact $l [expr {int(rand()*39)}]} 1000
193.114 microseconds per iteration
expect:~$ set s [lsort -integer $l]; puts foo
foo
expect:~$ time {lsearch -all -sorted -exact $s [expr {int(rand()*39)}]} 1000
170.89 microseconds per iteration
expect:~$ set s [lsort -integer $l]; puts foo
foo
expect:~$ time {lsearch -all -sorted -integer $s [expr {int(rand()*39)}]} 1000
103.633 microseconds per iteration
expect:~$ time {lsearch -all -integer -exact $s [expr {int(rand()*39)}]} 1000
104.209 microseconds per iteration
expect:~$ time {lsearch -all -integer -exact $l [expr {int(rand()*39)}]} 1000
106.351 microseconds per iteration
expect:~$

Re: faster Lsearch speed wanted

<tk0i2a$1fjoh$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: ric...@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: faster Lsearch speed wanted
Date: Thu, 3 Nov 2022 14:09:14 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 104
Message-ID: <tk0i2a$1fjoh$1@dont-email.me>
References: <15759bdf-5b81-4996-a51b-d8105117ba29n@googlegroups.com>
Injection-Date: Thu, 3 Nov 2022 14:09:14 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="ca7517c4c198df53244e613f9c634d51";
logging-data="1560337"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19J7nAcgDA9DrXw/cyKQAXp"
User-Agent: tin/2.0.1-20111224 ("Achenvoir") (UNIX) (Linux/3.10.17 (x86_64))
Cancel-Lock: sha1:RBCiAGBAAl1UViRGwnk86NXYlsE=
 by: Rich - Thu, 3 Nov 2022 14:09 UTC

rola...@gmail.com <rolance1@gmail.com> wrote:
> Hi all
>
> mass numbers analysis , need improve speed ...
>
> hope someone can give me some hint ,or other way search ....

As no one here knows what you are trying to achieve, we are limited in
our ability to offer suggestions.

> code list below
>
>
> set lst [lmap v [lrepeat 3125 1] {set v [expr int($v * [::tcl::mathfunc::rand]*39)]} ]
>
> ##### each number +id %39
> proc adv_chg_no_range4 {id lst} {
> set new_lst [lindex $lst 0]
> for {set i 1} {$i < [llength $lst]} {incr i} {
> set tmp_val [expr {([lindex $lst $i] + $id -1) % 39} ]
> if {$tmp_val == 0} {set tmp_val 39}
> lappend new_lst $tmp_val
> }
> return $new_lst
> }
>
>
>
>
> puts [time {
>
> foreach x {1 12 18 5 6} {
> lsearch -all -exact $lst $x
> }
>
> }
>
> ]
>
> puts "###combine ##"
>
> puts [time {
>
> foreach x {1 12 18 5 6} {
> lsearch -all [adv_chg_no_range4 1 $lst] $x
> }
>
> }
>
> ]\n
>
> puts "#### regexp"
> puts [time {lsearch -all -regexp $lst (^1$|^12$|^18$|^5$|^6$)}]
> puts "###combine ##"
> puts [time {lsearch -all -regexp [adv_chg_no_range4 1 $lst] (^1$|^12$|^18$|^5$|^6$)}
>
>
> output:
>
> 328 microseconds per iteration
> ###combine ##
> 4928 microseconds per iteration

Unsurprising here. The first does 5 searches over a static list.

The second makes 5 calls into a proc, that iterates the entire list via
foreach, returning a new list, and that new list is then searched.

Iterating the entire list, in Tcl, to generate a new list is where most
of this time difference is being consumed.

> #### regexp
> 1341 microseconds per iteration
> ###combine ##
> 2525 microseconds per iteration

Also unsurprising, searches using the regex engine will be slower than
searches using simple comparisons, because the regex engine does far
more than simple comparisons.

The time difference between the static list and the newly generated
list via a proc comments above also apply here.

> could someone give me direction to overcome speed issue

If your issue is lsearch speed, then:

1) only search a static list (i.e., don't recreate the list first
before searching it)

2) if your desired results can also be obtained from searching a sorted
list, then first sort the list (sort only once, then search plural
times). Using the -sorted option to lsearch causes lsearch to
perform a binary search of the list, which will be faster than
without -sorted, which causes lsearch to perform a linear search
(start at first element, look at each in sequence until found).

But you've failed to describe your actual problem. You've shown a
solution that does not work for you speed wise, but not described to us
what you are trying to achieve by this solution you've given. It is
quite possible there is some alternative way, without using lsearch, to
achieve your desired result, but we can't read your mind over Usenet to
know what your actual problem is to even be able to consider some
alternate.

Re: faster Lsearch speed wanted

<3c205bfe-427f-4724-9fb2-ed5c81c5c6b3n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a37:9246:0:b0:6fa:6e0c:e12 with SMTP id u67-20020a379246000000b006fa6e0c0e12mr6137298qkd.92.1667503157025;
Thu, 03 Nov 2022 12:19:17 -0700 (PDT)
X-Received: by 2002:a05:6214:20e6:b0:4bc:26a6:b6b7 with SMTP id
6-20020a05621420e600b004bc26a6b6b7mr8860269qvk.79.1667503156790; Thu, 03 Nov
2022 12:19:16 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.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: Thu, 3 Nov 2022 12:19:16 -0700 (PDT)
In-Reply-To: <45115fc7-f397-4b8b-8437-9cf324263085n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=103.77.4.199; posting-account=59xCUwoAAABx9tq6XUTZW-wQ1A7Z8t9L
NNTP-Posting-Host: 103.77.4.199
References: <15759bdf-5b81-4996-a51b-d8105117ba29n@googlegroups.com>
<b732b878-55b4-441a-948d-1ce93290f4a1n@googlegroups.com> <379b802a-6ecb-412b-967e-93d51a78545en@googlegroups.com>
<a7a61b1c-c881-4d43-b6c4-b2c9bcb00be0n@googlegroups.com> <45115fc7-f397-4b8b-8437-9cf324263085n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <3c205bfe-427f-4724-9fb2-ed5c81c5c6b3n@googlegroups.com>
Subject: Re: faster Lsearch speed wanted
From: rolan...@gmail.com (rola...@gmail.com)
Injection-Date: Thu, 03 Nov 2022 19:19:17 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 4408
 by: rola...@gmail.com - Thu, 3 Nov 2022 19:19 UTC

heinrichmartin 在 2022年11月4日 星期五凌晨12:49:33 [UTC+13] 的信中寫道:
> On Thursday, November 3, 2022 at 12:41:53 PM UTC+1, heinrichmartin wrote:
> > On Thursday, November 3, 2022 at 12:05:37 PM UTC+1, Rolance wrote:
> > > 3. single proc Vs combine proc the time consume not proportional ....
> > > still try to find out which affect momory occupy , not the simply code can get the best perforamce ...
> > > 5times faster than one line (-regexp ) code ....
> > Let me comment with a quote:
> >
> > On Thursday, August 13, 2020 at 9:07:54 AM UTC+2, Arjen wrote:
> > > [...] I do know that such benchmarks are notoriously difficult to get right. [...]
> Btw, here is my quick take on it (including a few cross-checks):
> expect:~$ set l [lmap x [lrepeat 10000 1] {expr {int(rand()*39)}}]; puts foo
> foo
> expect:~$ ll $l
> 10000
> expect:~$ lindex $l 25
> 22
> expect:~$ ::tcl::mathfunc::max {*}$l
> 38
> expect:~$ time {lsearch -all -integer $l [expr {int(rand()*39)}]} 1000
> 230.131 microseconds per iteration
> expect:~$ time {lsearch -all -exact $l [expr {int(rand()*39)}]} 1000
> 193.889 microseconds per iteration
> expect:~$ time {lsearch -all -integer $l [expr {int(rand()*39)}]} 1000
> 230.803 microseconds per iteration
> expect:~$ time {lsearch -all -exact $l [expr {int(rand()*39)}]} 1000
> 193.114 microseconds per iteration
> expect:~$ set s [lsort -integer $l]; puts foo
> foo
> expect:~$ time {lsearch -all -sorted -exact $s [expr {int(rand()*39)}]} 1000
> 170.89 microseconds per iteration
> expect:~$ set s [lsort -integer $l]; puts foo
> foo
> expect:~$ time {lsearch -all -sorted -integer $s [expr {int(rand()*39)}]} 1000
> 103.633 microseconds per iteration
> expect:~$ time {lsearch -all -integer -exact $s [expr {int(rand()*39)}]} 1000
> 104.209 microseconds per iteration
> expect:~$ time {lsearch -all -integer -exact $l [expr {int(rand()*39)}]} 1000
> 106.351 microseconds per iteration
> expect:~$

hi heinrichmartin

thank for your detail reply and try result

1. the data come from mass data file over 10G, each data line prefix with tile-id , that is why not use [lindex 0] data..
data must get form other source
2. need learch -all to get all value position , alreay try -inline and -regexp , the total running perfromnce less than simple -all

3. already view Tcl/coding/algorithms and do improve my program perviously , I think it the best solution , but customer not satisify with the speed
need get best performce for each proc code ....
lsearch can fit all request , or your have suggestion command to replace this with better perforamce.

4. will try all your suggestion later and repport the result

thanks
BR
Rolance

Re: faster Lsearch speed wanted

<34b60a93-2400-48ac-94b5-462e8a7e7b4dn@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:620a:28ce:b0:6cf:933c:40d3 with SMTP id l14-20020a05620a28ce00b006cf933c40d3mr22692863qkp.258.1667503523235;
Thu, 03 Nov 2022 12:25:23 -0700 (PDT)
X-Received: by 2002:a05:620a:2591:b0:6c9:cc85:87e3 with SMTP id
x17-20020a05620a259100b006c9cc8587e3mr23331906qko.577.1667503522928; Thu, 03
Nov 2022 12:25:22 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.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: Thu, 3 Nov 2022 12:25:22 -0700 (PDT)
In-Reply-To: <tk0i2a$1fjoh$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=103.77.4.199; posting-account=59xCUwoAAABx9tq6XUTZW-wQ1A7Z8t9L
NNTP-Posting-Host: 103.77.4.199
References: <15759bdf-5b81-4996-a51b-d8105117ba29n@googlegroups.com> <tk0i2a$1fjoh$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <34b60a93-2400-48ac-94b5-462e8a7e7b4dn@googlegroups.com>
Subject: Re: faster Lsearch speed wanted
From: rolan...@gmail.com (rola...@gmail.com)
Injection-Date: Thu, 03 Nov 2022 19:25:23 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 5125
 by: rola...@gmail.com - Thu, 3 Nov 2022 19:25 UTC

Rich 在 2022年11月4日 星期五凌晨3:09:19 [UTC+13] 的信中寫道:
> rola...@gmail.com <rola...@gmail.com> wrote:
> > Hi all
> >
> > mass numbers analysis , need improve speed ...
> >
> > hope someone can give me some hint ,or other way search ....
> As no one here knows what you are trying to achieve, we are limited in
> our ability to offer suggestions.
> > code list below
> >
> >
> > set lst [lmap v [lrepeat 3125 1] {set v [expr int($v * [::tcl::mathfunc::rand]*39)]} ]
> >
> > ##### each number +id %39
> > proc adv_chg_no_range4 {id lst} {
> > set new_lst [lindex $lst 0]
> > for {set i 1} {$i < [llength $lst]} {incr i} {
> > set tmp_val [expr {([lindex $lst $i] + $id -1) % 39} ]
> > if {$tmp_val == 0} {set tmp_val 39}
> > lappend new_lst $tmp_val
> > }
> > return $new_lst
> > }
> >
> >
> >
> >
> > puts [time {
> >
> > foreach x {1 12 18 5 6} {
> > lsearch -all -exact $lst $x
> > }
> >
> > }
> >
> > ]
> >
> > puts "###combine ##"
> >
> > puts [time {
> >
> > foreach x {1 12 18 5 6} {
> > lsearch -all [adv_chg_no_range4 1 $lst] $x
> > }
> >
> > }
> >
> > ]\n
> >
> > puts "#### regexp"
> > puts [time {lsearch -all -regexp $lst (^1$|^12$|^18$|^5$|^6$)}]
> > puts "###combine ##"
> > puts [time {lsearch -all -regexp [adv_chg_no_range4 1 $lst] (^1$|^12$|^18$|^5$|^6$)}
> >
> >
> > output:
> >
> > 328 microseconds per iteration
> > ###combine ##
> > 4928 microseconds per iteration
> Unsurprising here. The first does 5 searches over a static list.
>
> The second makes 5 calls into a proc, that iterates the entire list via
> foreach, returning a new list, and that new list is then searched.
>
> Iterating the entire list, in Tcl, to generate a new list is where most
> of this time difference is being consumed.
> > #### regexp
> > 1341 microseconds per iteration
> > ###combine ##
> > 2525 microseconds per iteration
> Also unsurprising, searches using the regex engine will be slower than
> searches using simple comparisons, because the regex engine does far
> more than simple comparisons.
>
> The time difference between the static list and the newly generated
> list via a proc comments above also apply here.
> > could someone give me direction to overcome speed issue
> If your issue is lsearch speed, then:
>
> 1) only search a static list (i.e., don't recreate the list first
> before searching it)
>
> 2) if your desired results can also be obtained from searching a sorted
> list, then first sort the list (sort only once, then search plural
> times). Using the -sorted option to lsearch causes lsearch to
> perform a binary search of the list, which will be faster than
> without -sorted, which causes lsearch to perform a linear search
> (start at first element, look at each in sequence until found).
>
> But you've failed to describe your actual problem. You've shown a
> solution that does not work for you speed wise, but not described to us
> what you are trying to achieve by this solution you've given. It is
> quite possible there is some alternative way, without using lsearch, to
> achieve your desired result, but we can't read your mind over Usenet to
> know what your actual problem is to even be able to consider some
> alternate.

Hi Rich

thanks for your advice
is possible relate memory occupy issue , see the running program get more an more memory after long time running...
will try all your suggestion later in real running program and give your detail reply

BR
Rolance

Re: faster Lsearch speed wanted

<69b8aece-4124-49fc-961a-e0a1c8239afan@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:ac8:708:0:b0:3a5:4cb1:7b2e with SMTP id g8-20020ac80708000000b003a54cb17b2emr8930339qth.175.1667553855026;
Fri, 04 Nov 2022 02:24:15 -0700 (PDT)
X-Received: by 2002:a37:b582:0:b0:6d2:c5d6:7055 with SMTP id
e124-20020a37b582000000b006d2c5d67055mr249690qkf.84.1667553756850; Fri, 04
Nov 2022 02:22:36 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.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: Fri, 4 Nov 2022 02:22:36 -0700 (PDT)
In-Reply-To: <45115fc7-f397-4b8b-8437-9cf324263085n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=103.77.4.199; posting-account=59xCUwoAAABx9tq6XUTZW-wQ1A7Z8t9L
NNTP-Posting-Host: 103.77.4.199
References: <15759bdf-5b81-4996-a51b-d8105117ba29n@googlegroups.com>
<b732b878-55b4-441a-948d-1ce93290f4a1n@googlegroups.com> <379b802a-6ecb-412b-967e-93d51a78545en@googlegroups.com>
<a7a61b1c-c881-4d43-b6c4-b2c9bcb00be0n@googlegroups.com> <45115fc7-f397-4b8b-8437-9cf324263085n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <69b8aece-4124-49fc-961a-e0a1c8239afan@googlegroups.com>
Subject: Re: faster Lsearch speed wanted
From: rolan...@gmail.com (rola...@gmail.com)
Injection-Date: Fri, 04 Nov 2022 09:24:15 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 6503
 by: rola...@gmail.com - Fri, 4 Nov 2022 09:22 UTC

heinrichmartin 在 2022年11月4日 星期五凌晨12:49:33 [UTC+13] 的信中寫道:
> On Thursday, November 3, 2022 at 12:41:53 PM UTC+1, heinrichmartin wrote:
> > On Thursday, November 3, 2022 at 12:05:37 PM UTC+1, Rolance wrote:
> > > 3. single proc Vs combine proc the time consume not proportional ....
> > > still try to find out which affect momory occupy , not the simply code can get the best perforamce ...
> > > 5times faster than one line (-regexp ) code ....
> > Let me comment with a quote:
> >
> > On Thursday, August 13, 2020 at 9:07:54 AM UTC+2, Arjen wrote:
> > > [...] I do know that such benchmarks are notoriously difficult to get right. [...]
> Btw, here is my quick take on it (including a few cross-checks):
> expect:~$ set l [lmap x [lrepeat 10000 1] {expr {int(rand()*39)}}]; puts foo
> foo
> expect:~$ ll $l
> 10000
> expect:~$ lindex $l 25
> 22
> expect:~$ ::tcl::mathfunc::max {*}$l
> 38
> expect:~$ time {lsearch -all -integer $l [expr {int(rand()*39)}]} 1000
> 230.131 microseconds per iteration
> expect:~$ time {lsearch -all -exact $l [expr {int(rand()*39)}]} 1000
> 193.889 microseconds per iteration
> expect:~$ time {lsearch -all -integer $l [expr {int(rand()*39)}]} 1000
> 230.803 microseconds per iteration
> expect:~$ time {lsearch -all -exact $l [expr {int(rand()*39)}]} 1000
> 193.114 microseconds per iteration
> expect:~$ set s [lsort -integer $l]; puts foo
> foo
> expect:~$ time {lsearch -all -sorted -exact $s [expr {int(rand()*39)}]} 1000
> 170.89 microseconds per iteration
> expect:~$ set s [lsort -integer $l]; puts foo
> foo
> expect:~$ time {lsearch -all -sorted -integer $s [expr {int(rand()*39)}]} 1000
> 103.633 microseconds per iteration
> expect:~$ time {lsearch -all -integer -exact $s [expr {int(rand()*39)}]} 1000
> 104.209 microseconds per iteration
> expect:~$ time {lsearch -all -integer -exact $l [expr {int(rand()*39)}]} 1000
> 106.351 microseconds per iteration
> expect:~$

Hi heinrichmartin

update code with your comment and test result below

set lst [lmap v [lrepeat 3125 1] {expr {int($v * [::tcl::mathfunc::rand]*39)}} ]

##### each number +id %39 first char title id
proc adv_chg_no_range4 {id lst} {
set new_lst [lindex $lst 0]
for {set i 1} {$i < [llength $lst]} {incr i} {
set tmp_val [expr {([lindex $lst $i] + $id -1) % 39} ]
if {$tmp_val == 0} {set tmp_val 39}
lappend new_lst $tmp_val
}
return $new_lst
}

proc adv_chg_no_range5 {id lst} {
set new_lst [lindex $lst 0]
incr id -1
lappend new_lst {*}[lmap v [lrange $lst 1 end] {
expr {(($v+$id)%-39)+39}
}]
return $new_lst
}

proc adv_chg_no_range6 {id lst} {
set new_lst [lindex $lst 0]
incr id -1
for {set i 1} {$i < [llength $lst]} {incr i} {
lappend new_lst [expr {(([lindex $lst $i]+$id)%-39)+39} ]
}
return $new_lst
}

puts [time {

foreach x {1 12 18 5 6} {
lsearch -all -exact $lst $x
}

}

]

puts "###combine ##"

puts [time {

foreach x {1 12 18 5 6} {
lsearch -all [adv_chg_no_range4 1 $lst] $x
}

}

]\n

puts "###combine static lst##"

puts [time {
set new [adv_chg_no_range4 1 $lst]
foreach x {1 12 18 5 6} {
lsearch -all $new $x
}

}

]\n

puts "#### regexp"
puts [time {lsearch -all -regexp $lst (^1$|^12$|^18$|^5$|^6$)}]
puts [time {lsearch -all -regexp $lst {^(?:1|12|18|5|6)$}}]
puts "###combine proc 4##"
puts [time {lsearch -all -regexp [adv_chg_no_range4 1 $lst] (^1$|^12$|^18$|^5$|^6$)}]
puts [time {lsearch -all -regexp [adv_chg_no_range4 1 $lst] {^(?:1|12|18|5|6)$}}]
puts "###combine proc 5##"
puts [time {lsearch -all -regexp [adv_chg_no_range5 1 $lst] (^1$|^12$|^18$|^5$|^6$)}]
puts [time {lsearch -all -regexp [adv_chg_no_range5 1 $lst] {^(?:1|12|18|5|6)$}}]
puts [time {lsearch -all -regexp $new {^(?:1|12|18|5|6)$}}]
puts "###combine proc 6##"
puts [time {lsearch -all -regexp [adv_chg_no_range6 1 $lst] (^1$|^12$|^18$|^5$|^6$)}]
puts [time {lsearch -all -regexp [adv_chg_no_range6 1 $lst] {^(?:1|12|18|5|6)$}}]

output

386 microseconds per iteration <<<<<
###combine ##
4807 microseconds per iteration

###combine static lst##
1069 microseconds per iteration <<<<<<<< 5 loop better than regexp but seem not stable ...

#### regexp
1311 microseconds per iteration
703 microseconds per iteration
###combine proc 4##
2550 microseconds per iteration
1797 microseconds per iteration
###combine proc 5##
1814 microseconds per iteration
1426 microseconds per iteration <<<<<< lmap get bests perforamce
942 microseconds per iteration <<<<<<<
###combine proc 6##
2091 microseconds per iteration
1633 microseconds per iteration

could you point me where still can improve .

thanks in advance

BR
Rolance

Re: faster Lsearch speed wanted

<2904068b-4bbf-4fcd-af46-089c2d8d57e0n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:ac8:7457:0:b0:3a5:4193:e722 with SMTP id h23-20020ac87457000000b003a54193e722mr13121416qtr.415.1667553982342;
Fri, 04 Nov 2022 02:26:22 -0700 (PDT)
X-Received: by 2002:a37:5882:0:b0:6f5:428d:f89c with SMTP id
m124-20020a375882000000b006f5428df89cmr252947qkb.11.1667553883339; Fri, 04
Nov 2022 02:24:43 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.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: Fri, 4 Nov 2022 02:24:43 -0700 (PDT)
In-Reply-To: <45115fc7-f397-4b8b-8437-9cf324263085n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=103.77.4.199; posting-account=59xCUwoAAABx9tq6XUTZW-wQ1A7Z8t9L
NNTP-Posting-Host: 103.77.4.199
References: <15759bdf-5b81-4996-a51b-d8105117ba29n@googlegroups.com>
<b732b878-55b4-441a-948d-1ce93290f4a1n@googlegroups.com> <379b802a-6ecb-412b-967e-93d51a78545en@googlegroups.com>
<a7a61b1c-c881-4d43-b6c4-b2c9bcb00be0n@googlegroups.com> <45115fc7-f397-4b8b-8437-9cf324263085n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <2904068b-4bbf-4fcd-af46-089c2d8d57e0n@googlegroups.com>
Subject: Re: faster Lsearch speed wanted
From: rolan...@gmail.com (rola...@gmail.com)
Injection-Date: Fri, 04 Nov 2022 09:26:22 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 6496
 by: rola...@gmail.com - Fri, 4 Nov 2022 09:24 UTC

heinrichmartin 在 2022年11月4日 星期五凌晨12:49:33 [UTC+13] 的信中寫道:
> On Thursday, November 3, 2022 at 12:41:53 PM UTC+1, heinrichmartin wrote:
> > On Thursday, November 3, 2022 at 12:05:37 PM UTC+1, Rolance wrote:
> > > 3. single proc Vs combine proc the time consume not proportional ....
> > > still try to find out which affect momory occupy , not the simply code can get the best perforamce ...
> > > 5times faster than one line (-regexp ) code ....
> > Let me comment with a quote:
> >
> > On Thursday, August 13, 2020 at 9:07:54 AM UTC+2, Arjen wrote:
> > > [...] I do know that such benchmarks are notoriously difficult to get right. [...]
> Btw, here is my quick take on it (including a few cross-checks):
> expect:~$ set l [lmap x [lrepeat 10000 1] {expr {int(rand()*39)}}]; puts foo
> foo
> expect:~$ ll $l
> 10000
> expect:~$ lindex $l 25
> 22
> expect:~$ ::tcl::mathfunc::max {*}$l
> 38
> expect:~$ time {lsearch -all -integer $l [expr {int(rand()*39)}]} 1000
> 230.131 microseconds per iteration
> expect:~$ time {lsearch -all -exact $l [expr {int(rand()*39)}]} 1000
> 193.889 microseconds per iteration
> expect:~$ time {lsearch -all -integer $l [expr {int(rand()*39)}]} 1000
> 230.803 microseconds per iteration
> expect:~$ time {lsearch -all -exact $l [expr {int(rand()*39)}]} 1000
> 193.114 microseconds per iteration
> expect:~$ set s [lsort -integer $l]; puts foo
> foo
> expect:~$ time {lsearch -all -sorted -exact $s [expr {int(rand()*39)}]} 1000
> 170.89 microseconds per iteration
> expect:~$ set s [lsort -integer $l]; puts foo
> foo
> expect:~$ time {lsearch -all -sorted -integer $s [expr {int(rand()*39)}]} 1000
> 103.633 microseconds per iteration
> expect:~$ time {lsearch -all -integer -exact $s [expr {int(rand()*39)}]} 1000
> 104.209 microseconds per iteration
> expect:~$ time {lsearch -all -integer -exact $l [expr {int(rand()*39)}]} 1000
> 106.351 microseconds per iteration
> expect:~$

Hi heinrichmartin

update code with your comment and test result below

set lst [lmap v [lrepeat 3125 1] {expr {int($v * [::tcl::mathfunc::rand]*39)}} ]

##### each number +id %39 first char title id
proc adv_chg_no_range4 {id lst} {
set new_lst [lindex $lst 0]
for {set i 1} {$i < [llength $lst]} {incr i} {
set tmp_val [expr {([lindex $lst $i] + $id -1) % 39} ]
if {$tmp_val == 0} {set tmp_val 39}
lappend new_lst $tmp_val
}
return $new_lst
}

proc adv_chg_no_range5 {id lst} {
set new_lst [lindex $lst 0]
incr id -1
lappend new_lst {*}[lmap v [lrange $lst 1 end] {
expr {(($v+$id)%-39)+39}
}]
return $new_lst
}

proc adv_chg_no_range6 {id lst} {
set new_lst [lindex $lst 0]
incr id -1
for {set i 1} {$i < [llength $lst]} {incr i} {
lappend new_lst [expr {(([lindex $lst $i]+$id)%-39)+39} ]
}
return $new_lst
}

puts [time {

foreach x {1 12 18 5 6} {
lsearch -all -exact $lst $x
}

}

]

puts "###combine ##"

puts [time {

foreach x {1 12 18 5 6} {
lsearch -all [adv_chg_no_range4 1 $lst] $x
}

}

]\n

puts "###combine static lst##"

puts [time {
set new [adv_chg_no_range4 1 $lst]
foreach x {1 12 18 5 6} {
lsearch -all $new $x
}

}

]\n

puts "#### regexp"
puts [time {lsearch -all -regexp $lst (^1$|^12$|^18$|^5$|^6$)}]
puts [time {lsearch -all -regexp $lst {^(?:1|12|18|5|6)$}}]
puts "###combine proc 4##"
puts [time {lsearch -all -regexp [adv_chg_no_range4 1 $lst] (^1$|^12$|^18$|^5$|^6$)}]
puts [time {lsearch -all -regexp [adv_chg_no_range4 1 $lst] {^(?:1|12|18|5|6)$}}]
puts "###combine proc 5##"
puts [time {lsearch -all -regexp [adv_chg_no_range5 1 $lst] (^1$|^12$|^18$|^5$|^6$)}]
puts [time {lsearch -all -regexp [adv_chg_no_range5 1 $lst] {^(?:1|12|18|5|6)$}}]
puts [time {lsearch -all -regexp $new {^(?:1|12|18|5|6)$}}]
puts "###combine proc 6##"
puts [time {lsearch -all -regexp [adv_chg_no_range6 1 $lst] (^1$|^12$|^18$|^5$|^6$)}]
puts [time {lsearch -all -regexp [adv_chg_no_range6 1 $lst] {^(?:1|12|18|5|6)$}}]

output

386 microseconds per iteration <<<<<
###combine ##
4807 microseconds per iteration

###combine static lst##
1069 microseconds per iteration <<<<<<<< 5 loop better than regexp but seem not stable ...

#### regexp
1311 microseconds per iteration
703 microseconds per iteration
###combine proc 4##
2550 microseconds per iteration
1797 microseconds per iteration
###combine proc 5##
1814 microseconds per iteration
1426 microseconds per iteration <<<<<< lmap get bests perforamce
942 microseconds per iteration <<<<<<<
###combine proc 6##
2091 microseconds per iteration
1633 microseconds per iteration

could you point me where still can improve .

thanks in advance

BR
Rolance

Re: faster Lsearch speed wanted

<acbe7761-bb5a-4310-b97d-4ed120b06428n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:ac8:7c86:0:b0:3a5:3ae2:e281 with SMTP id y6-20020ac87c86000000b003a53ae2e281mr15284027qtv.595.1667555109705;
Fri, 04 Nov 2022 02:45:09 -0700 (PDT)
X-Received: by 2002:a05:622a:5a19:b0:3a5:274c:6118 with SMTP id
fy25-20020a05622a5a1900b003a5274c6118mr257475qtb.425.1667555021419; Fri, 04
Nov 2022 02:43:41 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.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: Fri, 4 Nov 2022 02:43:41 -0700 (PDT)
In-Reply-To: <tk0i2a$1fjoh$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=103.77.4.199; posting-account=59xCUwoAAABx9tq6XUTZW-wQ1A7Z8t9L
NNTP-Posting-Host: 103.77.4.199
References: <15759bdf-5b81-4996-a51b-d8105117ba29n@googlegroups.com> <tk0i2a$1fjoh$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <acbe7761-bb5a-4310-b97d-4ed120b06428n@googlegroups.com>
Subject: Re: faster Lsearch speed wanted
From: rolan...@gmail.com (rola...@gmail.com)
Injection-Date: Fri, 04 Nov 2022 09:45:09 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 5398
 by: rola...@gmail.com - Fri, 4 Nov 2022 09:43 UTC

Rich 在 2022年11月4日 星期五凌晨3:09:19 [UTC+13] 的信中寫道:
> rola...@gmail.com <rola...@gmail.com> wrote:
> > Hi all
> >
> > mass numbers analysis , need improve speed ...
> >
> > hope someone can give me some hint ,or other way search ....
> As no one here knows what you are trying to achieve, we are limited in
> our ability to offer suggestions.
> > code list below
> >
> >
> > set lst [lmap v [lrepeat 3125 1] {set v [expr int($v * [::tcl::mathfunc::rand]*39)]} ]
> >
> > ##### each number +id %39
> > proc adv_chg_no_range4 {id lst} {
> > set new_lst [lindex $lst 0]
> > for {set i 1} {$i < [llength $lst]} {incr i} {
> > set tmp_val [expr {([lindex $lst $i] + $id -1) % 39} ]
> > if {$tmp_val == 0} {set tmp_val 39}
> > lappend new_lst $tmp_val
> > }
> > return $new_lst
> > }
> >
> >
> >
> >
> > puts [time {
> >
> > foreach x {1 12 18 5 6} {
> > lsearch -all -exact $lst $x
> > }
> >
> > }
> >
> > ]
> >
> > puts "###combine ##"
> >
> > puts [time {
> >
> > foreach x {1 12 18 5 6} {
> > lsearch -all [adv_chg_no_range4 1 $lst] $x
> > }
> >
> > }
> >
> > ]\n
> >
> > puts "#### regexp"
> > puts [time {lsearch -all -regexp $lst (^1$|^12$|^18$|^5$|^6$)}]
> > puts "###combine ##"
> > puts [time {lsearch -all -regexp [adv_chg_no_range4 1 $lst] (^1$|^12$|^18$|^5$|^6$)}
> >
> >
> > output:
> >
> > 328 microseconds per iteration
> > ###combine ##
> > 4928 microseconds per iteration
> Unsurprising here. The first does 5 searches over a static list.
>
> The second makes 5 calls into a proc, that iterates the entire list via
> foreach, returning a new list, and that new list is then searched.
>
> Iterating the entire list, in Tcl, to generate a new list is where most
> of this time difference is being consumed.
> > #### regexp
> > 1341 microseconds per iteration
> > ###combine ##
> > 2525 microseconds per iteration
> Also unsurprising, searches using the regex engine will be slower than
> searches using simple comparisons, because the regex engine does far
> more than simple comparisons.
>
> The time difference between the static list and the newly generated
> list via a proc comments above also apply here.
> > could someone give me direction to overcome speed issue
> If your issue is lsearch speed, then:
>
> 1) only search a static list (i.e., don't recreate the list first
> before searching it)
>
> 2) if your desired results can also be obtained from searching a sorted
> list, then first sort the list (sort only once, then search plural
> times). Using the -sorted option to lsearch causes lsearch to
> perform a binary search of the list, which will be faster than
> without -sorted, which causes lsearch to perform a linear search
> (start at first element, look at each in sequence until found).
>
> But you've failed to describe your actual problem. You've shown a
> solution that does not work for you speed wise, but not described to us
> what you are trying to achieve by this solution you've given. It is
> quite possible there is some alternative way, without using lsearch, to
> achieve your desired result, but we can't read your mind over Usenet to
> know what your actual problem is to even be able to consider some
> alternate.

Hi Rich

1. static list indeed faster , but need recreate lst for each analysis , how can improve this ... release memory ?

2 this actual problem is speed issue , all analysis result can fit request except the consume time , customer want cut half ...
adv_chg_no_range5 is the best performance
5 time loop search is better than regexp , but not stable..
(update code post pre , please refer)

could you point me some better or alterntive way to achieve speed request

thanks in advance
BR
Rolance

Re: faster Lsearch speed wanted

<ygawn8b6oe9.fsf@akutech.de>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: ralf...@gmx.de (Ralf Fassel)
Newsgroups: comp.lang.tcl
Subject: Re: faster Lsearch speed wanted
Date: Fri, 04 Nov 2022 10:48:46 +0100
Lines: 39
Message-ID: <ygawn8b6oe9.fsf@akutech.de>
References: <15759bdf-5b81-4996-a51b-d8105117ba29n@googlegroups.com>
<b732b878-55b4-441a-948d-1ce93290f4a1n@googlegroups.com>
<379b802a-6ecb-412b-967e-93d51a78545en@googlegroups.com>
<a7a61b1c-c881-4d43-b6c4-b2c9bcb00be0n@googlegroups.com>
<45115fc7-f397-4b8b-8437-9cf324263085n@googlegroups.com>
<2904068b-4bbf-4fcd-af46-089c2d8d57e0n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net Wq8eXmBn/HgSU/1qLNgi0Az4g59yZ1zpMLpbD1nFU795KPK+w=
Cancel-Lock: sha1:xhwga+PN3tGJhuRZCb11fZmsRbs= sha1:MyWWu719YbJTP+gXlk4YI68uHfg=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
 by: Ralf Fassel - Fri, 4 Nov 2022 09:48 UTC

* "rola...@gmail.com" <rolance1@gmail.com>
| ##### each number +id %39 first char title id
| proc adv_chg_no_range4 {id lst} {
| set new_lst [lindex $lst 0]
| for {set i 1} {$i < [llength $lst]} {incr i} {
| set tmp_val [expr {([lindex $lst $i] + $id -1) % 39} ]
| if {$tmp_val == 0} {set tmp_val 39}
| lappend new_lst $tmp_val
| }
| return $new_lst
| }
--<snip-snip>--
| proc adv_chg_no_range6 {id lst} {
| set new_lst [lindex $lst 0]
| incr id -1
| for {set i 1} {$i < [llength $lst]} {incr i} {
| lappend new_lst [expr {(([lindex $lst $i]+$id)%-39)+39} ]
| }
| return $new_lst
| }
--<snip-snip>--
| could you point me where still can improve .

Instead of traversing the list by index, use foreach:

for {set i 1} {$i < [llength $lst]} {incr i} {
set elt [lindex $lst $i]
...
}
=>
foreach elt [lrange $lst 1 end] {
...
}

But I have to admit I did not follow this thread to understand what your
ultimate goal is.

HTH
R'

Re: faster Lsearch speed wanted

<d9ad0a15-22ad-4cb6-a547-6b691e0044b1n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:6214:2483:b0:4bb:59ec:c5a7 with SMTP id gi3-20020a056214248300b004bb59ecc5a7mr31919954qvb.94.1667555918304;
Fri, 04 Nov 2022 02:58:38 -0700 (PDT)
X-Received: by 2002:ac8:64a:0:b0:3a5:3592:8d0c with SMTP id
e10-20020ac8064a000000b003a535928d0cmr16300547qth.138.1667555918094; Fri, 04
Nov 2022 02:58:38 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.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: Fri, 4 Nov 2022 02:58:37 -0700 (PDT)
In-Reply-To: <ygawn8b6oe9.fsf@akutech.de>
Injection-Info: google-groups.googlegroups.com; posting-host=103.77.4.199; posting-account=59xCUwoAAABx9tq6XUTZW-wQ1A7Z8t9L
NNTP-Posting-Host: 103.77.4.199
References: <15759bdf-5b81-4996-a51b-d8105117ba29n@googlegroups.com>
<b732b878-55b4-441a-948d-1ce93290f4a1n@googlegroups.com> <379b802a-6ecb-412b-967e-93d51a78545en@googlegroups.com>
<a7a61b1c-c881-4d43-b6c4-b2c9bcb00be0n@googlegroups.com> <45115fc7-f397-4b8b-8437-9cf324263085n@googlegroups.com>
<2904068b-4bbf-4fcd-af46-089c2d8d57e0n@googlegroups.com> <ygawn8b6oe9.fsf@akutech.de>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <d9ad0a15-22ad-4cb6-a547-6b691e0044b1n@googlegroups.com>
Subject: Re: faster Lsearch speed wanted
From: rolan...@gmail.com (rola...@gmail.com)
Injection-Date: Fri, 04 Nov 2022 09:58:38 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2903
 by: rola...@gmail.com - Fri, 4 Nov 2022 09:58 UTC

Ralf Fassel 在 2022年11月4日 星期五晚上10:48:51 [UTC+13] 的信中寫道:
> * "rola...@gmail.com" <rola...@gmail.com>
> | ##### each number +id %39 first char title id
> | proc adv_chg_no_range4 {id lst} {
> | set new_lst [lindex $lst 0]
> | for {set i 1} {$i < [llength $lst]} {incr i} {
> | set tmp_val [expr {([lindex $lst $i] + $id -1) % 39} ]
> | if {$tmp_val == 0} {set tmp_val 39}
> | lappend new_lst $tmp_val
> | }
> | return $new_lst
> | }
> --<snip-snip>--
> | proc adv_chg_no_range6 {id lst} {
> | set new_lst [lindex $lst 0]
> | incr id -1
> | for {set i 1} {$i < [llength $lst]} {incr i} {
> | lappend new_lst [expr {(([lindex $lst $i]+$id)%-39)+39} ]
> | }
> | return $new_lst
> | }
> --<snip-snip>--
> | could you point me where still can improve .
> Instead of traversing the list by index, use foreach:
> for {set i 1} {$i < [llength $lst]} {incr i} {
> set elt [lindex $lst $i]
> ...
> }
> =>
> foreach elt [lrange $lst 1 end] {
> ...
> }
>
> But I have to admit I did not follow this thread to understand what your
> ultimate goal is.
>
> HTH
> R'

Hi Ralf

thank for your suggestion , my goal is best lsearch performance
will try foreach will improve how much in multi analysis

BR
Rolance

Re: faster Lsearch speed wanted

<f308d464-c33d-4bdd-ad35-abf245fcfb93n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:620a:2806:b0:6b8:eced:ba3a with SMTP id f6-20020a05620a280600b006b8ecedba3amr25417063qkp.462.1667556985482;
Fri, 04 Nov 2022 03:16:25 -0700 (PDT)
X-Received: by 2002:ae9:ef15:0:b0:6fa:bb6:3485 with SMTP id
d21-20020ae9ef15000000b006fa0bb63485mr25217284qkg.322.1667556985325; Fri, 04
Nov 2022 03:16:25 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.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: Fri, 4 Nov 2022 03:16:25 -0700 (PDT)
In-Reply-To: <d9ad0a15-22ad-4cb6-a547-6b691e0044b1n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=84.115.226.75; posting-account=Od2xOAoAAACEyRX3Iu5rYt4oevuoeYUG
NNTP-Posting-Host: 84.115.226.75
References: <15759bdf-5b81-4996-a51b-d8105117ba29n@googlegroups.com>
<b732b878-55b4-441a-948d-1ce93290f4a1n@googlegroups.com> <379b802a-6ecb-412b-967e-93d51a78545en@googlegroups.com>
<a7a61b1c-c881-4d43-b6c4-b2c9bcb00be0n@googlegroups.com> <45115fc7-f397-4b8b-8437-9cf324263085n@googlegroups.com>
<2904068b-4bbf-4fcd-af46-089c2d8d57e0n@googlegroups.com> <ygawn8b6oe9.fsf@akutech.de>
<d9ad0a15-22ad-4cb6-a547-6b691e0044b1n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <f308d464-c33d-4bdd-ad35-abf245fcfb93n@googlegroups.com>
Subject: Re: faster Lsearch speed wanted
From: martin.h...@frequentis.com (heinrichmartin)
Injection-Date: Fri, 04 Nov 2022 10:16:25 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2397
 by: heinrichmartin - Fri, 4 Nov 2022 10:16 UTC

On Friday, November 4, 2022 at 10:58:40 AM UTC+1, rolance wrote:
> thank for your suggestion , my goal is best lsearch performance
> will try foreach will improve how much in multi analysis

Your claims are inconsistent, lsearch has no foreach.

Your initial problem ("Given a list of integers, find all matching integers fast.") is solved in this thread.
But your issues are somewhere else, e.g. reading data, transforming data, memory management.

Just one example: if you cannot accept multiple copies of your GBs of data, then you must transform the values in place (for & lindex & lset) or process them in a stream (i.e. do not create a list at all).

https://www.youtube.com/watch?v=c33AZBnRHks might describe an unexpectedly close problem (but we still don't know your exact objective). Anyway, the video contains quite some lessons about data handling/analysis.

Re: faster Lsearch speed wanted

<3a24e19d-aea0-4743-bcc4-a1b6f2eb48fbn@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:ad4:5fcd:0:b0:4bb:f8f2:1ebf with SMTP id jq13-20020ad45fcd000000b004bbf8f21ebfmr23542180qvb.66.1667559055130;
Fri, 04 Nov 2022 03:50:55 -0700 (PDT)
X-Received: by 2002:a05:622a:1ba5:b0:3a4:ffd9:22d8 with SMTP id
bp37-20020a05622a1ba500b003a4ffd922d8mr28271466qtb.356.1667559054946; Fri, 04
Nov 2022 03:50:54 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.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: Fri, 4 Nov 2022 03:50:54 -0700 (PDT)
In-Reply-To: <f308d464-c33d-4bdd-ad35-abf245fcfb93n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=103.77.4.199; posting-account=59xCUwoAAABx9tq6XUTZW-wQ1A7Z8t9L
NNTP-Posting-Host: 103.77.4.199
References: <15759bdf-5b81-4996-a51b-d8105117ba29n@googlegroups.com>
<b732b878-55b4-441a-948d-1ce93290f4a1n@googlegroups.com> <379b802a-6ecb-412b-967e-93d51a78545en@googlegroups.com>
<a7a61b1c-c881-4d43-b6c4-b2c9bcb00be0n@googlegroups.com> <45115fc7-f397-4b8b-8437-9cf324263085n@googlegroups.com>
<2904068b-4bbf-4fcd-af46-089c2d8d57e0n@googlegroups.com> <ygawn8b6oe9.fsf@akutech.de>
<d9ad0a15-22ad-4cb6-a547-6b691e0044b1n@googlegroups.com> <f308d464-c33d-4bdd-ad35-abf245fcfb93n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <3a24e19d-aea0-4743-bcc4-a1b6f2eb48fbn@googlegroups.com>
Subject: Re: faster Lsearch speed wanted
From: rolan...@gmail.com (rola...@gmail.com)
Injection-Date: Fri, 04 Nov 2022 10:50:55 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 3303
 by: rola...@gmail.com - Fri, 4 Nov 2022 10:50 UTC

heinrichmartin 在 2022年11月4日 星期五晚上11:16:27 [UTC+13] 的信中寫道:
> On Friday, November 4, 2022 at 10:58:40 AM UTC+1, rolance wrote:
> > thank for your suggestion , my goal is best lsearch performance
> > will try foreach will improve how much in multi analysis
> Your claims are inconsistent, lsearch has no foreach.
>
> Your initial problem ("Given a list of integers, find all matching integers fast.") is solved in this thread.
> But your issues are somewhere else, e.g. reading data, transforming data, memory management.
>
> Just one example: if you cannot accept multiple copies of your GBs of data, then you must transform the values in place (for & lindex & lset) or process them in a stream (i.e. do not create a list at all).
>
> https://www.youtube.com/watch?v=c33AZBnRHks might describe an unexpectedly close problem (but we still don't know your exact objective). Anyway, the video contains quite some lessons about data handling/analysis.

Hi heinrichmartin

thanks for your advice and reference video

my exact objective is improve the lsearch speed and your suggestion already help to raise 20% performance than original code , the lsearch is the key factor for the analysis program
in my statement contain some memory managemt may hace side effect , process them in a stream (over 1.6G have alloc issue ..) or multiple copies already try not better than existing code....
or you have better ideal for improve speed , accept all suggestion ^^
thanks

BR
Rolance

Re: faster Lsearch speed wanted

<tk33hu$1qd54$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: ric...@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: faster Lsearch speed wanted
Date: Fri, 4 Nov 2022 13:19:58 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 8
Message-ID: <tk33hu$1qd54$1@dont-email.me>
References: <15759bdf-5b81-4996-a51b-d8105117ba29n@googlegroups.com> <b732b878-55b4-441a-948d-1ce93290f4a1n@googlegroups.com> <379b802a-6ecb-412b-967e-93d51a78545en@googlegroups.com> <a7a61b1c-c881-4d43-b6c4-b2c9bcb00be0n@googlegroups.com> <45115fc7-f397-4b8b-8437-9cf324263085n@googlegroups.com> <2904068b-4bbf-4fcd-af46-089c2d8d57e0n@googlegroups.com> <ygawn8b6oe9.fsf@akutech.de>
Injection-Date: Fri, 4 Nov 2022 13:19:58 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="4e8ea44998da3f7d079b142bcda36cfb";
logging-data="1914020"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX184EgzRLTvYY3sJTIVAix6o"
User-Agent: tin/2.0.1-20111224 ("Achenvoir") (UNIX) (Linux/3.10.17 (x86_64))
Cancel-Lock: sha1:TePv9xzeoFfWbxSJw4aNVvB08Ew=
 by: Rich - Fri, 4 Nov 2022 13:19 UTC

Ralf Fassel <ralfixx@gmx.de> wrote:
> But I have to admit I did not follow this thread to understand what your
> ultimate goal is.

The OP has been asked what they are trying to achieve, multiple times.

No reply has ever done more than post yet another block of hard to
follow code with a faint "help me make this faster" request.

Re: faster Lsearch speed wanted

<tk33nk$1qd54$2@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: ric...@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: faster Lsearch speed wanted
Date: Fri, 4 Nov 2022 13:23:00 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 36
Message-ID: <tk33nk$1qd54$2@dont-email.me>
References: <15759bdf-5b81-4996-a51b-d8105117ba29n@googlegroups.com> <b732b878-55b4-441a-948d-1ce93290f4a1n@googlegroups.com> <379b802a-6ecb-412b-967e-93d51a78545en@googlegroups.com> <a7a61b1c-c881-4d43-b6c4-b2c9bcb00be0n@googlegroups.com> <45115fc7-f397-4b8b-8437-9cf324263085n@googlegroups.com> <2904068b-4bbf-4fcd-af46-089c2d8d57e0n@googlegroups.com> <ygawn8b6oe9.fsf@akutech.de> <d9ad0a15-22ad-4cb6-a547-6b691e0044b1n@googlegroups.com>
Injection-Date: Fri, 4 Nov 2022 13:23:00 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="4e8ea44998da3f7d079b142bcda36cfb";
logging-data="1914020"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Sh+ZBdoSYBAnzGtfz3Q1d"
User-Agent: tin/2.0.1-20111224 ("Achenvoir") (UNIX) (Linux/3.10.17 (x86_64))
Cancel-Lock: sha1:c1ThUyo82j9avBqMjOb6qOp3Qcs=
 by: Rich - Fri, 4 Nov 2022 13:23 UTC

rola...@gmail.com <rolance1@gmail.com> wrote:
> Ralf Fassel ? 2022?11?4? ?????10:48:51 [UTC+13] ??????
>> * "rola...@gmail.com" <rola...@gmail.com>
>> | could you point me where still can improve .
>> Instead of traversing the list by index, use foreach:
>> for {set i 1} {$i < [llength $lst]} {incr i} {
>> set elt [lindex $lst $i]
>> ...
>> }
>> =>
>> foreach elt [lrange $lst 1 end] {
>> ...
>> }
>>
>> But I have to admit I did not follow this thread to understand what your
>> ultimate goal is.
>>
>> HTH
>> R'
>
> Hi Ralf
>
> thank for your suggestion , my goal is best lsearch performance
> will try foreach will improve how much in multi analysis

No, that is not the answer to Ralf's question.

That is your current half-baked solution, but tells us nothing about
what you are trying to do beyond "faster lsearch". If we knew why you
were doing the lsearch (i.e., what the outer algorithm that is
searching this list is attempting to do) we might be able to suggest an
alternative.

As it is, you have a solution that does not work for you in your view,
and are only asking us to help tweak your solution -- without even
telling us enough to understand what that solution happens to be doing.

Re: faster Lsearch speed wanted

<tk344l$1qd54$3@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: ric...@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: faster Lsearch speed wanted
Date: Fri, 4 Nov 2022 13:29:57 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 82
Message-ID: <tk344l$1qd54$3@dont-email.me>
References: <15759bdf-5b81-4996-a51b-d8105117ba29n@googlegroups.com> <tk0i2a$1fjoh$1@dont-email.me> <acbe7761-bb5a-4310-b97d-4ed120b06428n@googlegroups.com>
Injection-Date: Fri, 4 Nov 2022 13:29:57 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="4e8ea44998da3f7d079b142bcda36cfb";
logging-data="1914020"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+9KZCaVxpXvG+QPxokTktZ"
User-Agent: tin/2.0.1-20111224 ("Achenvoir") (UNIX) (Linux/3.10.17 (x86_64))
Cancel-Lock: sha1:jy5SecZGI1KPD2ji+I/0cgSGsYg=
 by: Rich - Fri, 4 Nov 2022 13:29 UTC

rola...@gmail.com <rolance1@gmail.com> wrote:
> Rich ? 2022?11?4? ?????3:09:19 [UTC+13] ??????
>> rola...@gmail.com <rola...@gmail.com> wrote:
>> > Hi all
>> >
>> > mass numbers analysis , need improve speed ...
>> >
>> Unsurprising here. The first does 5 searches over a static list.
>>
>> The second makes 5 calls into a proc, that iterates the entire list via
>> foreach, returning a new list, and that new list is then searched.
>>
>> Iterating the entire list, in Tcl, to generate a new list is where most
>> of this time difference is being consumed.
>> > #### regexp
>> > 1341 microseconds per iteration
>> > ###combine ##
>> > 2525 microseconds per iteration
>> Also unsurprising, searches using the regex engine will be slower than
>> searches using simple comparisons, because the regex engine does far
>> more than simple comparisons.
>>
>> The time difference between the static list and the newly generated
>> list via a proc comments above also apply here.
>> > could someone give me direction to overcome speed issue
>> If your issue is lsearch speed, then:
>>
>> 1) only search a static list (i.e., don't recreate the list first
>> before searching it)
>>
>> 2) if your desired results can also be obtained from searching a sorted
>> list, then first sort the list (sort only once, then search plural
>> times). Using the -sorted option to lsearch causes lsearch to
>> perform a binary search of the list, which will be faster than
>> without -sorted, which causes lsearch to perform a linear search
>> (start at first element, look at each in sequence until found).
>>
>> But you've failed to describe your actual problem. You've shown a
>> solution that does not work for you speed wise, but not described to us
>> what you are trying to achieve by this solution you've given. It is
>> quite possible there is some alternative way, without using lsearch, to
>> achieve your desired result, but we can't read your mind over Usenet to
>> know what your actual problem is to even be able to consider some
>> alternate.
>
>
> Hi Rich
>
> 1. static list indeed faster , but need recreate lst for each
> analysis , how can improve this ... release memory ?

Please explain to us why you need to recreate the list for each
analysis. We see no reason yet why this is necessary (and don't simply
say "because I need to do so" -- that will not be an acceptable
answer).

You can't 'release memory' manually with Tcl, that is all automatic.

> 2 this actual problem is speed issue , all analysis result can fit
> request except the consume time , customer want cut half ...

No, the actual problem is whatever it is you are trying to do. You've
never told us that, other than a meaningless "analysis". If you had
told us the actual problem, we would then bee ablle

> adv_chg_no_range5 is the best performance
> 5 time loop search is better than regexp , but not stable..
> (update code post pre , please refer)
>
> could you point me some better or alterntive way to achieve speed
> request

Not unless you explain why you need to recreate the list, and what
outer reason you need to iterate the list each time to recreate it
instead of re-creating one copy then searching that plural times.

And, if you'd ever bother to tell us what you are really trying to do,
there might be a better faster way with a change in how you represent
the data. But you've never given us anything but your vague
statements, so there is no way for us to recognize a superior way of
representing the data that would increase speed (assuming such a way
does exist).

Re: faster Lsearch speed wanted

<5349d37c-58b9-4557-bf07-3d8225197a9cn@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a37:c24c:0:b0:6fa:769b:8d7b with SMTP id j12-20020a37c24c000000b006fa769b8d7bmr7241699qkm.304.1667592814251;
Fri, 04 Nov 2022 13:13:34 -0700 (PDT)
X-Received: by 2002:a05:622a:83:b0:39c:fa14:efeb with SMTP id
o3-20020a05622a008300b0039cfa14efebmr30596536qtw.643.1667592814079; Fri, 04
Nov 2022 13:13:34 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.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: Fri, 4 Nov 2022 13:13:33 -0700 (PDT)
In-Reply-To: <tk344l$1qd54$3@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=103.77.5.121; posting-account=59xCUwoAAABx9tq6XUTZW-wQ1A7Z8t9L
NNTP-Posting-Host: 103.77.5.121
References: <15759bdf-5b81-4996-a51b-d8105117ba29n@googlegroups.com>
<tk0i2a$1fjoh$1@dont-email.me> <acbe7761-bb5a-4310-b97d-4ed120b06428n@googlegroups.com>
<tk344l$1qd54$3@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <5349d37c-58b9-4557-bf07-3d8225197a9cn@googlegroups.com>
Subject: Re: faster Lsearch speed wanted
From: rolan...@gmail.com (rola...@gmail.com)
Injection-Date: Fri, 04 Nov 2022 20:13:34 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 6446
 by: rola...@gmail.com - Fri, 4 Nov 2022 20:13 UTC

Rich 在 2022年11月5日 星期六凌晨2:30:01 [UTC+13] 的信中寫道:
> rola...@gmail.com <rola...@gmail.com> wrote:
> > Rich ? 2022?11?4? ?????3:09:19 [UTC+13] ??????
> >> rola...@gmail.com <rola...@gmail.com> wrote:
> >> > Hi all
> >> >
> >> > mass numbers analysis , need improve speed ...
> >> >
> >> Unsurprising here. The first does 5 searches over a static list.
> >>
> >> The second makes 5 calls into a proc, that iterates the entire list via
> >> foreach, returning a new list, and that new list is then searched.
> >>
> >> Iterating the entire list, in Tcl, to generate a new list is where most
> >> of this time difference is being consumed.
> >> > #### regexp
> >> > 1341 microseconds per iteration
> >> > ###combine ##
> >> > 2525 microseconds per iteration
> >> Also unsurprising, searches using the regex engine will be slower than
> >> searches using simple comparisons, because the regex engine does far
> >> more than simple comparisons.
> >>
> >> The time difference between the static list and the newly generated
> >> list via a proc comments above also apply here.
> >> > could someone give me direction to overcome speed issue
> >> If your issue is lsearch speed, then:
> >>
> >> 1) only search a static list (i.e., don't recreate the list first
> >> before searching it)
> >>
> >> 2) if your desired results can also be obtained from searching a sorted
> >> list, then first sort the list (sort only once, then search plural
> >> times). Using the -sorted option to lsearch causes lsearch to
> >> perform a binary search of the list, which will be faster than
> >> without -sorted, which causes lsearch to perform a linear search
> >> (start at first element, look at each in sequence until found).
> >>
> >> But you've failed to describe your actual problem. You've shown a
> >> solution that does not work for you speed wise, but not described to us
> >> what you are trying to achieve by this solution you've given. It is
> >> quite possible there is some alternative way, without using lsearch, to
> >> achieve your desired result, but we can't read your mind over Usenet to
> >> know what your actual problem is to even be able to consider some
> >> alternate.
> >
> >
> > Hi Rich
> >
> > 1. static list indeed faster , but need recreate lst for each
> > analysis , how can improve this ... release memory ?
> Please explain to us why you need to recreate the list for each
> analysis. We see no reason yet why this is necessary (and don't simply
> say "because I need to do so" -- that will not be an acceptable
> answer).
>
> You can't 'release memory' manually with Tcl, that is all automatic.
> > 2 this actual problem is speed issue , all analysis result can fit
> > request except the consume time , customer want cut half ...
> No, the actual problem is whatever it is you are trying to do. You've
> never told us that, other than a meaningless "analysis". If you had
> told us the actual problem, we would then bee ablle
> > adv_chg_no_range5 is the best performance
> > 5 time loop search is better than regexp , but not stable..
> > (update code post pre , please refer)
> >
> > could you point me some better or alterntive way to achieve speed
> > request
> Not unless you explain why you need to recreate the list, and what
> outer reason you need to iterate the list each time to recreate it
> instead of re-creating one copy then searching that plural times.
>
> And, if you'd ever bother to tell us what you are really trying to do,
> there might be a better faster way with a change in how you represent
> the data. But you've never given us anything but your vague
> statements, so there is no way for us to recognize a superior way of
> representing the data that would increase speed (assuming such a way
> does exist).

Hi Rich

thanks for your advice .

("Given a list of integers, find all matching integers fast." with position ) is what I look for.
this main program is customize lottary prediction and analysis system ,
customer made some rule to recreate list number , and find the best position hit the target , also reference history record up to "N" previous hit.

that is what i need recreate it each time.... original program for N phase 3125x3125x39x1 time comparison upto 7hr..
with some shortcut and optimize code already down to 396 sec. but customer not satisify ---> need 60 sec with single thread... his ideal cal qty 3125x3125x39x600 for one time...

previousily he tell me other C++ program can achieve (but different rule, my code more rules)

already separate data create with mass file , only source file and change each number +1 for 39 sift range...

do it's limitation of tcl , or some way can faster calculate .

BR
Rolance

Re: faster Lsearch speed wanted

<tk4096$216mh$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!rocksolid2!i2pn.org!aioe.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: ric...@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: faster Lsearch speed wanted
Date: Fri, 4 Nov 2022 21:30:15 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 81
Message-ID: <tk4096$216mh$1@dont-email.me>
References: <15759bdf-5b81-4996-a51b-d8105117ba29n@googlegroups.com> <tk0i2a$1fjoh$1@dont-email.me> <acbe7761-bb5a-4310-b97d-4ed120b06428n@googlegroups.com> <tk344l$1qd54$3@dont-email.me> <5349d37c-58b9-4557-bf07-3d8225197a9cn@googlegroups.com>
Injection-Date: Fri, 4 Nov 2022 21:30:15 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="4e8ea44998da3f7d079b142bcda36cfb";
logging-data="2136785"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+6aJqCTvsp/y18wpWV2Mjc"
User-Agent: tin/2.0.1-20111224 ("Achenvoir") (UNIX) (Linux/3.10.17 (x86_64))
Cancel-Lock: sha1:t0grNOJ4Y0zXkV66I67EliplJow=
 by: Rich - Fri, 4 Nov 2022 21:30 UTC

rola...@gmail.com <rolance1@gmail.com> wrote:
> Hi Rich
>
> thanks for your advice .
>
> ("Given a list of integers, find all matching integers fast." with
> position ) is what I look for. this main program is customize
> lottary prediction and analysis system , customer made some rule to
> recreate list number , and find the best position hit the target ,
> also reference history record up to "N" previous hit.
>
> that is what i need recreate it each time.... original program for N
> phase 3125x3125x39x1 time comparison upto 7hr.. with some
> shortcut and optimize code already down to 396 sec. but customer not
> satisify ---> need 60 sec with single thread... his ideal cal qty
> 3125x3125x39x600 for one time...

Do you mean it searches for the positions in 228 515 625 000 (228
billion) total numbers?

For a list that takes 396 sec, what is the 'llength' result of running
llength on that list?

> previousily he tell me other C++ program can achieve (but different
> rule, my code more rules)

C++ is also a compiled program. That very likely gives it a
performance edge from the start.

> already separate data create with mass file , only source file and
> change each number +1 for 39 sift range...
>
> do it's limitation of tcl , or some way can faster calculate .

So you have a list of length X (what is a typical X value?) of numbers
from 1 to 39, and you want to find all occurrences of a given number
and return the positions of all those numbers in that list?

I.e, consider this code:

$ rlwrap tclsh
% package require sqlite3
3.35.5
% sqlite3 db :memory:
% db eval {create table list (id integer primary key, num integer);}

This below inserts five million numbers that are randomly chosen
between 1 and 39:

% for {set i 0} {$i < 5000000} {incr i} { db eval "insert into list (num) values ([expr {int(rand()*39+1)}]);"}

Create an index on the "num" column:

% db eval {create index idx on list(num);}

Do some "searching", the 'result' of these queries will be the
"position" of each value being requested:

% time {db eval {select id from list where num = 20;}}
22530 microseconds per iteration
% time {db eval {select id from list where num = 20;}}
22827 microseconds per iteration
% time {db eval {select id from list where num = 27;}}
22856 microseconds per iteration
% time {db eval {select id from list where num = 5;}}
22711 microseconds per iteration

Pretty consistent, about 22.5ms to find the "positions" of all the
numbers equal to 20 (or 27 or 5) in the "list" of five million
possibilities. Memory consumption, as reported by top, is 332Meg.

This is what I meant when I asked you to tell us the problem you were
trying to solve, instead of giving us your "solution", keeping the
actual problem secret, and asking us to help fix the solution. You do
yourself no favors that way, and prevent us from being able to suggest
superior alternatives.

In the code above I am finding the "positions" of numbers in an
"ordered list" of five million entries in about 22.5ms above. Now,
granted, I am not doing anything with those positions, but the
alternate "lsearch" above is extremely fast.

Re: faster Lsearch speed wanted

<dfc0a6c9-eae5-47f4-a293-6f3f9958ef22n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a0c:b351:0:b0:4bc:9ed:6fe6 with SMTP id a17-20020a0cb351000000b004bc09ed6fe6mr24614312qvf.76.1667601085975;
Fri, 04 Nov 2022 15:31:25 -0700 (PDT)
X-Received: by 2002:a05:622a:1144:b0:3a5:24af:bc27 with SMTP id
f4-20020a05622a114400b003a524afbc27mr25285757qty.425.1667601085790; Fri, 04
Nov 2022 15:31:25 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.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: Fri, 4 Nov 2022 15:31:25 -0700 (PDT)
In-Reply-To: <tk4096$216mh$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=103.77.5.121; posting-account=59xCUwoAAABx9tq6XUTZW-wQ1A7Z8t9L
NNTP-Posting-Host: 103.77.5.121
References: <15759bdf-5b81-4996-a51b-d8105117ba29n@googlegroups.com>
<tk0i2a$1fjoh$1@dont-email.me> <acbe7761-bb5a-4310-b97d-4ed120b06428n@googlegroups.com>
<tk344l$1qd54$3@dont-email.me> <5349d37c-58b9-4557-bf07-3d8225197a9cn@googlegroups.com>
<tk4096$216mh$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <dfc0a6c9-eae5-47f4-a293-6f3f9958ef22n@googlegroups.com>
Subject: Re: faster Lsearch speed wanted
From: rolan...@gmail.com (rola...@gmail.com)
Injection-Date: Fri, 04 Nov 2022 22:31:25 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 5212
 by: rola...@gmail.com - Fri, 4 Nov 2022 22:31 UTC

Rich 在 2022年11月5日 星期六上午10:30:18 [UTC+13] 的信中寫道:
> rola...@gmail.com <rola...@gmail.com> wrote:
> > Hi Rich
> >
> > thanks for your advice .
> >
> > ("Given a list of integers, find all matching integers fast." with
> > position ) is what I look for. this main program is customize
> > lottary prediction and analysis system , customer made some rule to
> > recreate list number , and find the best position hit the target ,
> > also reference history record up to "N" previous hit.
> >
> > that is what i need recreate it each time.... original program for N
> > phase 3125x3125x39x1 time comparison upto 7hr.. with some
> > shortcut and optimize code already down to 396 sec. but customer not
> > satisify ---> need 60 sec with single thread... his ideal cal qty
> > 3125x3125x39x600 for one time...
> Do you mean it searches for the positions in 228 515 625 000 (228
> billion) total numbers?
>
> For a list that takes 396 sec, what is the 'llength' result of running
> llength on that list?
> > previousily he tell me other C++ program can achieve (but different
> > rule, my code more rules)
> C++ is also a compiled program. That very likely gives it a
> performance edge from the start.
> > already separate data create with mass file , only source file and
> > change each number +1 for 39 sift range...
> >
> > do it's limitation of tcl , or some way can faster calculate .
> So you have a list of length X (what is a typical X value?) of numbers
> from 1 to 39, and you want to find all occurrences of a given number
> and return the positions of all those numbers in that list?
>
> I.e, consider this code:
>
> $ rlwrap tclsh
> % package require sqlite3
> 3.35.5
> % sqlite3 db :memory:
> % db eval {create table list (id integer primary key, num integer);}
>
> This below inserts five million numbers that are randomly chosen
> between 1 and 39:
>
> % for {set i 0} {$i < 5000000} {incr i} { db eval "insert into list (num) values ([expr {int(rand()*39+1)}]);"}
>
> Create an index on the "num" column:
>
> % db eval {create index idx on list(num);}
>
> Do some "searching", the 'result' of these queries will be the
> "position" of each value being requested:
>
> % time {db eval {select id from list where num = 20;}}
> 22530 microseconds per iteration
> % time {db eval {select id from list where num = 20;}}
> 22827 microseconds per iteration
> % time {db eval {select id from list where num = 27;}}
> 22856 microseconds per iteration
> % time {db eval {select id from list where num = 5;}}
> 22711 microseconds per iteration
>
> Pretty consistent, about 22.5ms to find the "positions" of all the
> numbers equal to 20 (or 27 or 5) in the "list" of five million
> possibilities. Memory consumption, as reported by top, is 332Meg.
>
> This is what I meant when I asked you to tell us the problem you were
> trying to solve, instead of giving us your "solution", keeping the
> actual problem secret, and asking us to help fix the solution. You do
> yourself no favors that way, and prevent us from being able to suggest
> superior alternatives.
>
> In the code above I am finding the "positions" of numbers in an
> "ordered list" of five million entries in about 22.5ms above. Now,
> granted, I am not doing anything with those positions, but the
> alternate "lsearch" above is extremely fast.

hi Rich

great thanks for your advice

will change data structure to sqlite get faster speed .

BR
Rolance

Re: faster Lsearch speed wanted

<f98229e5-24d6-4805-a959-3954d98b95dbn@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:ad4:5f4f:0:b0:4bb:e056:b0d8 with SMTP id p15-20020ad45f4f000000b004bbe056b0d8mr30680555qvg.80.1667608106908;
Fri, 04 Nov 2022 17:28:26 -0700 (PDT)
X-Received: by 2002:ac8:64a:0:b0:3a5:3592:8d0c with SMTP id
e10-20020ac8064a000000b003a535928d0cmr19352193qth.138.1667608106736; Fri, 04
Nov 2022 17:28:26 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.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: Fri, 4 Nov 2022 17:28:26 -0700 (PDT)
In-Reply-To: <dfc0a6c9-eae5-47f4-a293-6f3f9958ef22n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=103.77.5.121; posting-account=59xCUwoAAABx9tq6XUTZW-wQ1A7Z8t9L
NNTP-Posting-Host: 103.77.5.121
References: <15759bdf-5b81-4996-a51b-d8105117ba29n@googlegroups.com>
<tk0i2a$1fjoh$1@dont-email.me> <acbe7761-bb5a-4310-b97d-4ed120b06428n@googlegroups.com>
<tk344l$1qd54$3@dont-email.me> <5349d37c-58b9-4557-bf07-3d8225197a9cn@googlegroups.com>
<tk4096$216mh$1@dont-email.me> <dfc0a6c9-eae5-47f4-a293-6f3f9958ef22n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <f98229e5-24d6-4805-a959-3954d98b95dbn@googlegroups.com>
Subject: Re: faster Lsearch speed wanted
From: rolan...@gmail.com (rola...@gmail.com)
Injection-Date: Sat, 05 Nov 2022 00:28:26 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 7955
 by: rola...@gmail.com - Sat, 5 Nov 2022 00:28 UTC

rola...@gmail.com 在 2022年11月5日 星期六上午11:31:28 [UTC+13] 的信中寫道:
> Rich 在 2022年11月5日 星期六上午10:30:18 [UTC+13] 的信中寫道:
> > rola...@gmail.com <rola...@gmail.com> wrote:
> > > Hi Rich
> > >
> > > thanks for your advice .
> > >
> > > ("Given a list of integers, find all matching integers fast." with
> > > position ) is what I look for. this main program is customize
> > > lottary prediction and analysis system , customer made some rule to
> > > recreate list number , and find the best position hit the target ,
> > > also reference history record up to "N" previous hit.
> > >
> > > that is what i need recreate it each time.... original program for N
> > > phase 3125x3125x39x1 time comparison upto 7hr.. with some
> > > shortcut and optimize code already down to 396 sec. but customer not
> > > satisify ---> need 60 sec with single thread... his ideal cal qty
> > > 3125x3125x39x600 for one time...
> > Do you mean it searches for the positions in 228 515 625 000 (228
> > billion) total numbers?
> >
> > For a list that takes 396 sec, what is the 'llength' result of running
> > llength on that list?
> > > previousily he tell me other C++ program can achieve (but different
> > > rule, my code more rules)
> > C++ is also a compiled program. That very likely gives it a
> > performance edge from the start.
> > > already separate data create with mass file , only source file and
> > > change each number +1 for 39 sift range...
> > >
> > > do it's limitation of tcl , or some way can faster calculate .
> > So you have a list of length X (what is a typical X value?) of numbers
> > from 1 to 39, and you want to find all occurrences of a given number
> > and return the positions of all those numbers in that list?
> >
> > I.e, consider this code:
> >
> > $ rlwrap tclsh
> > % package require sqlite3
> > 3.35.5
> > % sqlite3 db :memory:
> > % db eval {create table list (id integer primary key, num integer);}
> >
> > This below inserts five million numbers that are randomly chosen
> > between 1 and 39:
> >
> > % for {set i 0} {$i < 5000000} {incr i} { db eval "insert into list (num) values ([expr {int(rand()*39+1)}]);"}
> >
> > Create an index on the "num" column:
> >
> > % db eval {create index idx on list(num);}
> >
> > Do some "searching", the 'result' of these queries will be the
> > "position" of each value being requested:
> >
> > % time {db eval {select id from list where num = 20;}}
> > 22530 microseconds per iteration
> > % time {db eval {select id from list where num = 20;}}
> > 22827 microseconds per iteration
> > % time {db eval {select id from list where num = 27;}}
> > 22856 microseconds per iteration
> > % time {db eval {select id from list where num = 5;}}
> > 22711 microseconds per iteration
> >
> > Pretty consistent, about 22.5ms to find the "positions" of all the
> > numbers equal to 20 (or 27 or 5) in the "list" of five million
> > possibilities. Memory consumption, as reported by top, is 332Meg.
> >
> > This is what I meant when I asked you to tell us the problem you were
> > trying to solve, instead of giving us your "solution", keeping the
> > actual problem secret, and asking us to help fix the solution. You do
> > yourself no favors that way, and prevent us from being able to suggest
> > superior alternatives.
> >
> > In the code above I am finding the "positions" of numbers in an
> > "ordered list" of five million entries in about 22.5ms above. Now,
> > granted, I am not doing anything with those positions, but the
> > alternate "lsearch" above is extremely fast.
> hi Rich
>
> great thanks for your advice
>
> will change data structure to sqlite get faster speed .
>
>
> BR
> Rolance

hi Rich

below code with my test result
could you point me what wrong same code with different output

package require sqlite3

console show

set lst [lmap v [lrepeat 3125 1] {expr {int($v * [::tcl::mathfunc::rand]*39)}} ]

proc adv_chg_no_range5 {id lst} {
set new_lst [lindex $lst 0]
incr id -1
lappend new_lst {*}[lmap v [lrange $lst 1 end] {
expr {(($v+$id)%-39)+39}
}]
return $new_lst
}

puts "#### db ####"

sqlite3 db :memory:

db eval {create table list (id integer primary key, num integer);}

for {set i 0} {$i < 3125} {incr i} { db eval "insert into list (num) values ([expr {int(rand()*39+1)}]);"}

db eval {create index idx on list(num);}

puts [time {db eval {select id from list where num = 20;}}]
puts [time {db eval {select id from list where num = 1;}}]
puts [time {db eval {select id from list where num = 36;}}]
puts [time {db eval {select id from list where num = 6;}}]
puts [time {db eval {select id from list where num = 23;}}]

db close

puts "#### db1 ####"

sqlite3 db1 :memory:
db1 eval {create table list (id integer primary key, num integer);}

#### use $lst performance not ideal ---> mark use same data source
#foreach x [adv_chg_no_range5 1 $lst] {
# db1 eval "insert into list (num) values ($x);"
#}

for {set i 0} {$i < 3125} {incr i} { db1 eval "insert into list (num) values ([expr {int(rand()*39+1)}]);"}

puts [time {db1 eval {select id from list where num = 20;}}]
puts [time {db1 eval {select id from list where num = 1;}}]
puts [time {db1 eval {select id from list where num = 36;}}]
puts [time {db1 eval {select id from list where num = 6;}}]
puts [time {db1 eval {select id from list where num = 23;}}]

db1 close

####output ###

#### db ####
36 microseconds per iteration
86 microseconds per iteration
89 microseconds per iteration
92 microseconds per iteration
93 microseconds per iteration
#### db1 #### <<<<<< over 3 times
195 microseconds per iteration
240 microseconds per iteration
219 microseconds per iteration
221 microseconds per iteration
234 microseconds per iteration

BR
Rolance

Re: faster Lsearch speed wanted

<tk4gfm$24sn0$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: ric...@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: faster Lsearch speed wanted
Date: Sat, 5 Nov 2022 02:06:46 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 54
Message-ID: <tk4gfm$24sn0$1@dont-email.me>
References: <15759bdf-5b81-4996-a51b-d8105117ba29n@googlegroups.com> <tk0i2a$1fjoh$1@dont-email.me> <acbe7761-bb5a-4310-b97d-4ed120b06428n@googlegroups.com> <tk344l$1qd54$3@dont-email.me> <5349d37c-58b9-4557-bf07-3d8225197a9cn@googlegroups.com> <tk4096$216mh$1@dont-email.me> <dfc0a6c9-eae5-47f4-a293-6f3f9958ef22n@googlegroups.com> <f98229e5-24d6-4805-a959-3954d98b95dbn@googlegroups.com>
Injection-Date: Sat, 5 Nov 2022 02:06:46 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="4de48e840dd1beb592d0118b3a8de78d";
logging-data="2257632"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19aLMdRGAzu/B6AXrryJlQF"
User-Agent: tin/2.0.1-20111224 ("Achenvoir") (UNIX) (Linux/3.10.17 (x86_64))
Cancel-Lock: sha1:6LCUDHP7XFr2p7dRHwpF9sGHjC0=
 by: Rich - Sat, 5 Nov 2022 02:06 UTC

rola...@gmail.com <rolance1@gmail.com> wrote:
> rola...@gmail.com ? 2022?11?5? ?????11:31:28 [UTC+13] ??????
>> Rich ? 2022?11?5? ?????10:30:18 [UTC+13] ??????
>> > I.e, consider this code:
>> >
>> > $ rlwrap tclsh
>> > % package require sqlite3
>> > 3.35.5
>> > % sqlite3 db :memory:
>> > % db eval {create table list (id integer primary key, num integer);}
>> >
>> > This below inserts five million numbers that are randomly chosen
>> > between 1 and 39:
>> >
>> > % for {set i 0} {$i < 5000000} {incr i} { db eval "insert into list (num) values ([expr {int(rand()*39+1)}]);"}
>> >
>> > Create an index on the "num" column:
>> >
>> > % db eval {create index idx on list(num);}
>> >
>> > Do some "searching", the 'result' of these queries will be the
>> > "position" of each value being requested:
>> >
>> > % time {db eval {select id from list where num = 20;}}
>> > 22530 microseconds per iteration
>> > % time {db eval {select id from list where num = 20;}}
>> > 22827 microseconds per iteration
>> > % time {db eval {select id from list where num = 27;}}
>> > 22856 microseconds per iteration
>> > % time {db eval {select id from list where num = 5;}}
>> > 22711 microseconds per iteration
>> >
>> > Pretty consistent, about 22.5ms to find the "positions" of all the
>> > numbers equal to 20 (or 27 or 5) in the "list" of five million
>> > possibilities. Memory consumption, as reported by top, is 332Meg.
>
> hi Rich
>
> below code with my test result
> could you point me what wrong same code with different output

db1 and db2 are not the same code.

Your db2 code omits creating an index on the num column.

Without the index sqlite has to scan all the rows in the table.

With the index it can refer to the index and (effectively) directly
pull out the matching rows.

That is the reason for the time difference. The index consumes some
up-front time to build, in order to significantly accelerate lookups
later.

Re: faster Lsearch speed wanted

<bd07520e-5455-4a98-8f2a-9929d6181398n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:ad4:5bee:0:b0:4bb:eaab:1a5e with SMTP id k14-20020ad45bee000000b004bbeaab1a5emr29772713qvc.40.1667641969256;
Sat, 05 Nov 2022 02:52:49 -0700 (PDT)
X-Received: by 2002:a05:620a:28cd:b0:6cf:93b3:a78 with SMTP id
l13-20020a05620a28cd00b006cf93b30a78mr28908849qkp.11.1667641969056; Sat, 05
Nov 2022 02:52:49 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.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, 5 Nov 2022 02:52:48 -0700 (PDT)
In-Reply-To: <tk4gfm$24sn0$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=103.77.5.121; posting-account=59xCUwoAAABx9tq6XUTZW-wQ1A7Z8t9L
NNTP-Posting-Host: 103.77.5.121
References: <15759bdf-5b81-4996-a51b-d8105117ba29n@googlegroups.com>
<tk0i2a$1fjoh$1@dont-email.me> <acbe7761-bb5a-4310-b97d-4ed120b06428n@googlegroups.com>
<tk344l$1qd54$3@dont-email.me> <5349d37c-58b9-4557-bf07-3d8225197a9cn@googlegroups.com>
<tk4096$216mh$1@dont-email.me> <dfc0a6c9-eae5-47f4-a293-6f3f9958ef22n@googlegroups.com>
<f98229e5-24d6-4805-a959-3954d98b95dbn@googlegroups.com> <tk4gfm$24sn0$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <bd07520e-5455-4a98-8f2a-9929d6181398n@googlegroups.com>
Subject: Re: faster Lsearch speed wanted
From: rolan...@gmail.com (rola...@gmail.com)
Injection-Date: Sat, 05 Nov 2022 09:52:49 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 4271
 by: rola...@gmail.com - Sat, 5 Nov 2022 09:52 UTC

Rich 在 2022年11月5日 星期六下午3:06:51 [UTC+13] 的信中寫道:
> rola...@gmail.com <rola...@gmail.com> wrote:
> > rola...@gmail.com ? 2022?11?5? ?????11:31:28 [UTC+13] ??????
> >> Rich ? 2022?11?5? ?????10:30:18 [UTC+13] ??????
> >> > I.e, consider this code:
> >> >
> >> > $ rlwrap tclsh
> >> > % package require sqlite3
> >> > 3.35.5
> >> > % sqlite3 db :memory:
> >> > % db eval {create table list (id integer primary key, num integer);}
> >> >
> >> > This below inserts five million numbers that are randomly chosen
> >> > between 1 and 39:
> >> >
> >> > % for {set i 0} {$i < 5000000} {incr i} { db eval "insert into list (num) values ([expr {int(rand()*39+1)}]);"}
> >> >
> >> > Create an index on the "num" column:
> >> >
> >> > % db eval {create index idx on list(num);}
> >> >
> >> > Do some "searching", the 'result' of these queries will be the
> >> > "position" of each value being requested:
> >> >
> >> > % time {db eval {select id from list where num = 20;}}
> >> > 22530 microseconds per iteration
> >> > % time {db eval {select id from list where num = 20;}}
> >> > 22827 microseconds per iteration
> >> > % time {db eval {select id from list where num = 27;}}
> >> > 22856 microseconds per iteration
> >> > % time {db eval {select id from list where num = 5;}}
> >> > 22711 microseconds per iteration
> >> >
> >> > Pretty consistent, about 22.5ms to find the "positions" of all the
> >> > numbers equal to 20 (or 27 or 5) in the "list" of five million
> >> > possibilities. Memory consumption, as reported by top, is 332Meg.
> >
> > hi Rich
> >
> > below code with my test result
> > could you point me what wrong same code with different output
> db1 and db2 are not the same code.
>
> Your db2 code omits creating an index on the num column.
>
> Without the index sqlite has to scan all the rows in the table.
>
> With the index it can refer to the index and (effectively) directly
> pull out the matching rows.
>
> That is the reason for the time difference. The index consumes some
> up-front time to build, in order to significantly accelerate lookups
> later.

hi Rich

thank for the detail explanation ,
single test program have great performance , but in real multi-program implement speed not better than previous Lsearch code .....
still debug what factor will affect speed ...

thanks for great help , if you have some hint about program interactive affect , please point me

BR
Rolance

Re: faster Lsearch speed wanted

<tk5ndg$2fcs0$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: ric...@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: faster Lsearch speed wanted
Date: Sat, 5 Nov 2022 13:11:13 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 33
Message-ID: <tk5ndg$2fcs0$1@dont-email.me>
References: <15759bdf-5b81-4996-a51b-d8105117ba29n@googlegroups.com> <tk0i2a$1fjoh$1@dont-email.me> <acbe7761-bb5a-4310-b97d-4ed120b06428n@googlegroups.com> <tk344l$1qd54$3@dont-email.me> <5349d37c-58b9-4557-bf07-3d8225197a9cn@googlegroups.com> <tk4096$216mh$1@dont-email.me> <dfc0a6c9-eae5-47f4-a293-6f3f9958ef22n@googlegroups.com> <f98229e5-24d6-4805-a959-3954d98b95dbn@googlegroups.com> <tk4gfm$24sn0$1@dont-email.me> <bd07520e-5455-4a98-8f2a-9929d6181398n@googlegroups.com>
Injection-Date: Sat, 5 Nov 2022 13:11:13 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="4de48e840dd1beb592d0118b3a8de78d";
logging-data="2601856"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/e5/Lbl8+PzBl8RcYpp6BP"
User-Agent: tin/2.0.1-20111224 ("Achenvoir") (UNIX) (Linux/3.10.17 (x86_64))
Cancel-Lock: sha1:p1lY/lcI5zymk+XpRqAZJSIzMFU=
 by: Rich - Sat, 5 Nov 2022 13:11 UTC

rola...@gmail.com <rolance1@gmail.com> wrote:
> Rich ? 2022?11?5? ?????3:06:51 [UTC+13] ??????
>> rola...@gmail.com <rola...@gmail.com> wrote:
>> Your db2 code omits creating an index on the num column.
>>
>> Without the index sqlite has to scan all the rows in the table.
>>
>> With the index it can refer to the index and (effectively) directly
>> pull out the matching rows.
>>
>> That is the reason for the time difference. The index consumes some
>> up-front time to build, in order to significantly accelerate lookups
>> later.
>
> hi Rich
>
> thank for the detail explanation ,
> single test program have great performance , but in real
> multi-program implement speed not better than previous Lsearch code
> ..... still debug what factor will affect speed ...

I also asked how long the list was in the real world program, and as
you have done so many times in this thread, you ignored that question
entirely. If you continue ignoring direct questions that would allow
us to help you I will plonk you.

In the real program, how long is the list that is being searched?

> thanks for great help , if you have some hint about program
> interactive affect , please point me

We can't help if you do not give us the information we need to be able
to effectively help.

Pages:12
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor