Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

BOFH excuse #293: You must've hit the wrong any key.


comp / comp.lang.tcl / Re: How to speed up a script by threading?

SubjectAuthor
* How to speed up a script by threading?Mark Summerfield
+* Re: How to speed up a script by threading?Ralf Fassel
|`- Re: How to speed up a script by threading?saito
`- Re: How to speed up a script by threading?Harald Oehlmann

1
Subject: How to speed up a script by threading?
From: Mark Summerfield
Newsgroups: comp.lang.tcl
Date: Fri, 19 Jul 2024 08:14 UTC
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!border-2.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-2.nntp.ord.giganews.com!nntp.brightview.co.uk!news.brightview.co.uk.POSTED!not-for-mail
NNTP-Posting-Date: Fri, 19 Jul 2024 08:14:38 +0000
From: mark@qtrac.eu (Mark Summerfield)
Subject: How to speed up a script by threading?
Newsgroups: comp.lang.tcl
MIME-Version: 1.0
User-Agent: Pan/0.154 (Izium; 517acf4)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Message-ID: <nkmdnbODp8_zvQf7nZ2dnZfqn_udnZ2d@brightview.co.uk>
Date: Fri, 19 Jul 2024 08:14:38 +0000
Lines: 94
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-qZNFJ07MRE17A+hWrS9/0dgQPw0Qthv1nBy/vqApvrGSEsSXm7GMTB1zzfa1Z4I4XDYRRPw7TUGFGNw!LZi36QYJMf4L5fteLCZMXftIa7yp3Ob2m+Fr87rYK3jsG68O9aWZVUHF7/MQGHFmu2N6T0OU8UNo!bO0v2OJDLsQkbIHQRIy27y7jAA==
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
View all headers

The program below (~95 LOC) is very slow.
One way to speed it up would be to process each directory given on the
command line in its own thread.
But I can't see how to do this.
Or is there a better way to make it faster?
I'm using Tcl/Tk 9.0b2 on Linux.

#!/usr/bin/env tclsh9

package require fileutil 1

namespace eval ef {}

proc ef::main {} {
lassign [read_args] patterns dirs debug ;# may not return
if {$debug} {
puts "globs='$patterns'"
}
set filenames [list]
foreach dir $dirs {
if {$debug} {
puts "folder='$dir'"
}
foreach filename [fileutil::findByPattern $dir $patterns] {
lappend filenames $filename
}
}
foreach filename [lsort $filenames] {
puts $filename
}
}

proc ef::read_args {} {
set what ""
set dirs [list]
set debug false
foreach arg $::argv {
switch $arg {
-h -
--help {usage}
-D -
--debug {set debug true}
default {
if {$what eq ""} {
set what $arg
} else {
lappend dirs $arg
}
}
}
}
if {$what eq ""} {
usage
}
set patterns [get_patterns $what]
if {![llength $dirs]} {
lappend dirs .
}
return [list $patterns $dirs $debug]
}

proc ef::usage {} {
puts $::USAGE
exit 1
}

proc ef::get_patterns what {
if {[string index $what 0] ne "."} {
return "*$what*"
}
set patterns [list *$what]
switch $what {
.c {lappend patterns *.h}
.c++ {lappend patterns *.h *.hxx *.hpp *.h++ *.cxx *.cpp}
.cpp {lappend patterns *.h *.hxx *.hpp *.h++ *.cxx *.c++}
.tcl {lappend patterns *.tm}
.py {lappend patterns *.pyw}
}
return $patterns
}

const USAGE {usage: efind.tcl [options] <what> [dir1 [dir2 …]]

options:
-h, --help Show this usage message and quit.
-D, --debug Show pattern and folders being processed.

Searches for files that match \"what\" in . or in any specified
folders, including recursively into subfolders.
\"what\" is either \".ext\" or text, e.g., .tcl or .py; or go.mod;
for .tcl searches *.{tcl,tm}, for .py *.{py,pyw}, for .c *.{c,h}
for .cpp or .c++ *.{h,hxx,hpp,h++,cxx,cpp,c++}; others as is.}

ef::main

Subject: Re: How to speed up a script by threading?
From: Ralf Fassel
Newsgroups: comp.lang.tcl
Date: Fri, 19 Jul 2024 09:08 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: ralfixx@gmx.de (Ralf Fassel)
Newsgroups: comp.lang.tcl
Subject: Re: How to speed up a script by threading?
Date: Fri, 19 Jul 2024 11:08:14 +0200
Lines: 23
Message-ID: <ygaikx13g1t.fsf@akutech.de>
References: <nkmdnbODp8_zvQf7nZ2dnZfqn_udnZ2d@brightview.co.uk>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net TIG3deCnKjmrC4FvFzHdHwk/1Pl8lXt+wTKzYRVu1qdvefE1Y=
Cancel-Lock: sha1:p3wLHE3n4wsMJVAINwNqoePiNtc= sha1:VkglbZgdm8dbh5c9G9++KN2igo8= sha256:Qn8MCD70oirSZHA0oGAq1Uqwzf2fv07yZisuK3FBkqo=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
View all headers

* Mark Summerfield <mark@qtrac.eu>
| The program below (~95 LOC) is very slow.
| One way to speed it up would be to process each directory given on the
| command line in its own thread.
| But I can't see how to do this.
| Or is there a better way to make it faster?
| I'm using Tcl/Tk 9.0b2 on Linux.

Since you give the directories on the (linux) commandline, put the
one-thread-per-dir one level up:

Instead of
your-prog dir1 dir2 dir3 ...
do
for dir in dir1 dir2 dir3 ... ; do
your-prog $dir &
done

That way multiple processes (not threads) run in parallel,
and you don't have to change the program at all.

My 0.02.
R'

Subject: Re: How to speed up a script by threading?
From: Harald Oehlmann
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Fri, 19 Jul 2024 10:04 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: wortkarg3@yahoo.com (Harald Oehlmann)
Newsgroups: comp.lang.tcl
Subject: Re: How to speed up a script by threading?
Date: Fri, 19 Jul 2024 12:04:59 +0200
Organization: A noiseless patient Spider
Lines: 112
Message-ID: <v7ddob$2sdtg$1@dont-email.me>
References: <nkmdnbODp8_zvQf7nZ2dnZfqn_udnZ2d@brightview.co.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 19 Jul 2024 12:05:00 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="55c35c63d22da0328d710718c4a97c3f";
logging-data="3028912"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+LpU9NtfRFOGxooNgVV7Pn"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:R298nbRJohlgSHE6wi+pQK1QxMU=
Content-Language: en-GB
In-Reply-To: <nkmdnbODp8_zvQf7nZ2dnZfqn_udnZ2d@brightview.co.uk>
View all headers

Am 19.07.2024 um 10:14 schrieb Mark Summerfield:
> The program below (~95 LOC) is very slow.
> One way to speed it up would be to process each directory given on the
> command line in its own thread.
> But I can't see how to do this.
> Or is there a better way to make it faster?
> I'm using Tcl/Tk 9.0b2 on Linux.
>
> #!/usr/bin/env tclsh9
>
> package require fileutil 1
>
> namespace eval ef {}
>
> proc ef::main {} {
> lassign [read_args] patterns dirs debug ;# may not return
> if {$debug} {
> puts "globs='$patterns'"
> }
> set filenames [list]
> foreach dir $dirs {
> if {$debug} {
> puts "folder='$dir'"
> }
> foreach filename [fileutil::findByPattern $dir $patterns] {
> lappend filenames $filename
> }
> }
> foreach filename [lsort $filenames] {
> puts $filename
> }
> }
>
> proc ef::read_args {} {
> set what ""
> set dirs [list]
> set debug false
> foreach arg $::argv {
> switch $arg {
> -h -
> --help {usage}
> -D -
> --debug {set debug true}
> default {
> if {$what eq ""} {
> set what $arg
> } else {
> lappend dirs $arg
> }
> }
> }
> }
> if {$what eq ""} {
> usage
> }
> set patterns [get_patterns $what]
> if {![llength $dirs]} {
> lappend dirs .
> }
> return [list $patterns $dirs $debug]
> }
>
> proc ef::usage {} {
> puts $::USAGE
> exit 1
> }
>
> proc ef::get_patterns what {
> if {[string index $what 0] ne "."} {
> return "*$what*"
> }
> set patterns [list *$what]
> switch $what {
> .c {lappend patterns *.h}
> .c++ {lappend patterns *.h *.hxx *.hpp *.h++ *.cxx *.cpp}
> .cpp {lappend patterns *.h *.hxx *.hpp *.h++ *.cxx *.c++}
> .tcl {lappend patterns *.tm}
> .py {lappend patterns *.pyw}
> }
> return $patterns
> }
>
> const USAGE {usage: efind.tcl [options] <what> [dir1 [dir2 …]]
>
> options:
> -h, --help Show this usage message and quit.
> -D, --debug Show pattern and folders being processed.
>
> Searches for files that match \"what\" in . or in any specified
> folders, including recursively into subfolders.
> \"what\" is either \".ext\" or text, e.g., .tcl or .py; or go.mod;
> for .tcl searches *.{tcl,tm}, for .py *.{py,pyw}, for .c *.{c,h}
> for .cpp or .c++ *.{h,hxx,hpp,h++,cxx,cpp,c++}; others as is.}
>
> ef::main

Hi Mark,

great that you are so active. The tootip stuff is sorted out and all
issues are corrected, thank you for that.

The diagram issue is open.

About threads, you may use threads with TCL using the Thread package.
That is again a long story. You first need the normally bundled
extension "thread" (package require thread). Then you can create threads
and charge trhem with TCL scripts and get the results together.

Harald

Subject: Re: How to speed up a script by threading?
From: saito
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Fri, 19 Jul 2024 12:51 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: saitology9@gmail.com (saito)
Newsgroups: comp.lang.tcl
Subject: Re: How to speed up a script by threading?
Date: Fri, 19 Jul 2024 08:51:22 -0400
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <v7dngb$304h2$2@dont-email.me>
References: <nkmdnbODp8_zvQf7nZ2dnZfqn_udnZ2d@brightview.co.uk>
<ygaikx13g1t.fsf@akutech.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 19 Jul 2024 14:51:23 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="09a7543eeb8e416b4785832a856f53c4";
logging-data="3150370"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+gFXnlkYX5YRxmTpDikj8G"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:8Cc8Tbc6wnDOAeOfay9Y5FyoWhI=
In-Reply-To: <ygaikx13g1t.fsf@akutech.de>
Content-Language: en-US
View all headers

On 7/19/2024 5:08 AM, Ralf Fassel wrote:
> * Mark Summerfield <mark@qtrac.eu>
> | The program below (~95 LOC) is very slow.
> | One way to speed it up would be to process each directory given on the
> | command line in its own thread.
> | But I can't see how to do this.
> | Or is there a better way to make it faster?
> | I'm using Tcl/Tk 9.0b2 on Linux.
>
> Since you give the directories on the (linux) commandline, put the
> one-thread-per-dir one level up:
>

On linux, it might be easier to just do "find"; it is quite fast.

1

rocksolid light 0.9.8
clearnet tor