Re: How to speed up a script by threading?

Liste des GroupesRevenir à cl tcl 
Sujet : Re: How to speed up a script by threading?
De : wortkarg3 (at) *nospam* yahoo.com (Harald Oehlmann)
Groupes : comp.lang.tcl
Date : 19. Jul 2024, 11:04:59
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v7ddob$2sdtg$1@dont-email.me>
References : 1
User-Agent : Mozilla Thunderbird
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

Date Sujet#  Auteur
19 Jul 24 * How to speed up a script by threading?4Mark Summerfield
19 Jul 24 +* Re: How to speed up a script by threading?2Ralf Fassel
19 Jul 24 i`- Re: How to speed up a script by threading?1saito
19 Jul 24 `- Re: How to speed up a script by threading?1Harald Oehlmann

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal