Re: Tcl faster than Perl/Python...but only with tricks...



Ian Bell wrote:
I am no expert but presumably, not matter what the language, the gets or
read ends up as an fgets C library call.

Certainly not! fgets() is a part of stdio and Tcl doesn't use that
because it's buffering interacts badly with use of select() in Tcl's
notifier. Instead, Tcl manages everything over the OS's syscall level
(i.e. read() or recv() on Unix, depending on channel type) so that it
can get the interaction between the various pieces right.

If you want a speed boost, make sure that the channel is configured to
use -translation binary and use [read]. That turns off a lot of
processing that would otherwise slow things down. Also, if your file is
only a few percent of your available physical address space in size,
then slurping it all into memory is best anyway. :-)

Is it possible the differences are
due in part to the way each language sets up the channel e.g buffer size,
blocking, no chars read in fgets etc?

The differences quite possibly also relate to how languages handle their
internal string representations. Processing as byte arrays is definitely
faster (though wrong with some rare system encodings, but I bet Tcl does
better with those than other languages do). As noted above, put the
channel in binary mode (8.5 will make this easier to do BTW) and then
use [read] for a speed boost.

Donal.
.



Relevant Pages

  • Re: Fedora Linux and Tcl/Tk problems
    ... translation and encoding configuration on the $fileID ... nicely by some shortcuts modern Tcl supports for binary channels. ... which signals at the time you open the channel that you ... look at the time stamps, that note was answered BEFORE it was ...
    (comp.lang.tcl)
  • TIP #219: Tcl Channel Reflection API
    ... TIP #219: TCL CHANNEL REFLECTION API ... command') and also an independent companion to the forthcoming TIPs on ...
    (comp.lang.tcl)
  • Re: readable callback blocking invoked when theres nothing to read
    ... I'm not a proficient TCL ... the buffering layer matters. ... Fortunately, in Tcl things are different, because all channel ... TCL socket protocol didn't use the callback mechanism. ...
    (comp.lang.tcl)
  • changing I/O channels
    ... I've done in the Altogether simulator for the Xerox Alto: ... Tcl runs in its own thread. ... on channel with refCount> 0". ... But surely it must be the act of registering the channel, ...
    (comp.lang.tcl)
  • Re: changing I/O channels
    ... the following is based on my understanding of TCL ... When we create a channel token, ... The standard channels are different: ... "stdout" and "stderr" make pairs with tokens whose handles ...
    (comp.lang.tcl)