Re: Tcl faster than Perl/Python...but only with tricks...
- From: Stephan Kuhagen <stk@xxxxxxxxxx>
- Date: Sun, 31 Dec 2006 14:38:27 +0100
Uwe Klein wrote:
(This is actually broken because the searchterm will not be found....
if it spans a block boundary, )
fconfigure $f -encoding binary -translation binary
I found that setting binary for encoding and translation slows things down.
This really surprises me. What are your differences, when using binary and
not?
And it is also of course broken, because it also prints lines without the
pattern, for example if the whole file contains 10 lines, but is only 1k in
size and only one line contains the pattern, then your proc prints the
whole file...
But using [read] in a loop for smaller chunks so they fit into memory is a
good solution. I combined it with gets to get around the problem of finding
line endings by myself a got a real speedup compared to gets alone. This is
even faster that the pure read/regexp version which was the fastest until
now. Really cool, thanks for the inspiration... ;-) Here the fastest
version so far:
---
proc grep {} {
set f [open bigfile r]
while { [set chunk [read $f 65536]] != "" } {
if {[string index $chunk end] != "\n" } {
append chunk [gets $f]
}
puts -nonewline [join
[regexp -all -inline -linestop -nocase .*destroy.*\n} $chunk] {}]
}
}
---
This runs 0.229s compared to only using gets (0.672s) or with reading the
whole file and then using regexp (0.232s). And of course, this can run even
a little bit faster by changing the chunks size. This one really beats
Perl... Fun. ;-)
Regards
Stephan
.
- References:
- Tcl faster than Perl/Python...but only with tricks...
- From: Stephan Kuhagen
- Re: Tcl faster than Perl/Python...but only with tricks...
- From: George Petasis
- Re: Tcl faster than Perl/Python...but only with tricks...
- From: Stephan Kuhagen
- Re: Tcl faster than Perl/Python...but only with tricks...
- From: Alexandre Ferrieux
- Re: Tcl faster than Perl/Python...but only with tricks...
- From: Stephan Kuhagen
- Re: Tcl faster than Perl/Python...but only with tricks...
- From: Uwe Klein
- Re: Tcl faster than Perl/Python...but only with tricks...
- From: Alexandre Ferrieux
- Re: Tcl faster than Perl/Python...but only with tricks...
- From: Uwe Klein
- Tcl faster than Perl/Python...but only with tricks...
- Prev by Date: Re: Tcl faster than Perl/Python...but only with tricks... [Idea?]
- Next by Date: Re: Tcl faster than Perl/Python...but only with tricks...
- Previous by thread: Re: Tcl faster than Perl/Python...but only with tricks...
- Next by thread: Re: Tcl faster than Perl/Python...but only with tricks...
- Index(es):
Relevant Pages
|