Deutsch   English   Français   Italiano  
<v7ddob$2sdtg$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Harald Oehlmann <wortkarg3@yahoo.com>
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>
Bytes: 4231

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