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



Alexandre Ferrieux wrote:
Uwe Klein a écrit :

Just for the fun of it:
I changed the [gets $fd line] to [set line [read $fd 65536]].
the difference is negligible.


Ha ! This one seems to point to my suggestion about some
post-processing done in the channel code (encoding or crlf). Can you
try with -translation binary, and also play around with various
-encoding values ?

Also, another interesting comparison point would be stdio's
fread()/fgets(). Not sure 'grep' uses it though (does anybody know
whether Perl and Python do ?). You may need to compile a 3-line C
program to test...

-Alex

He he:
(This is actually broken because the searchterm will not be found
if it spans a block boundary, )

#!/usr/bin/tclsh


proc matchdestroy {fd} {
while { [set line [read $fd 65536]] != "" } {
if {[string match -nocase "*destroy*" $line]} {
puts $line
}
}
}
set f [open bigfile r]

fconfigure $f -encoding binary -translation binary

matchdestroy $f
#end

real 0m0.207s
user 0m0.162s
sys 0m0.045s

the same applied to the initial procified [gets] example
runs for:
real 0m0.668s
user 0m0.654s
sys 0m0.014s

.



Relevant Pages