alias filetest {
var %ticks = $ticks
.fopen filetest $1-
if (!$ferr) {
window -h @test
while (!$feof) aline @test . $fread(filetest)
window -c @test
}
.fclose filetest
echo -a File handling commands time taken: $calc($ticks - %ticks) ms.
return
:error
if (*command halted* iswm $error) {
close -@ @test
if ($fopen(filetest)) .fclose $v1
}
}
alias filtertest {
var %ticks = $ticks
window -h @test
filter -fw $1- @test
window -c @test
echo -a Filter command time taken: $calc($ticks - %ticks) ms.
}
alias test {
var %file = $qt($scriptdir $+ 2007.07.fflog.txt)
filetest %file
filtertest %file
}
File handling commands time taken: 13172 ms.
Filter command time taken: 4172 ms.
File handling commands time taken: 13093 ms.
Filter command time taken: 4094 ms.
File handling commands time taken: 13141 ms.
Filter command time taken: 4094 ms.
Filter is just over three times as fast each time.
Now the test is not 100% fair you could say, because with the file handling one I've added a "." to each line.. the reason for this is that some of your lines are blank and it seemed quicker to add a . than to check each line exists with if ().
Here's one that uses if () for arguments sake:
alias filetest {
var %ticks = $ticks
.fopen filetest $1-
if (!$ferr) {
window -h @test
while (!$feof) {
if ($fread(filetest)) aline @test $v1
}
window -c @test
}
.fclose filetest
echo -a File handling commands time taken: $calc($ticks - %ticks) ms.
return
:error
if (*command halted* iswm $error) {
close -@ @test
if ($fopen(filetest)) .fclose $v1
}
}
alias filtertest {
var %ticks = $ticks
window -h @test
filter -fw $1- @test
window -c @test
echo -a Filter command time taken: $calc($ticks - %ticks) ms.
}
alias test {
var %file = $qt($scriptdir $+ 2007.07.fflog.txt)
filetest %file
filtertest %file
}
File handling commands time taken: 13922 ms.
Filter command time taken: 4093 ms.
File handling commands time taken: 13953 ms.
Filter command time taken: 4094 ms.
File handling commands time taken: 13938 ms.
Filter command time taken: 4094 ms.
Still three times faster..
And here's one that filters to NUL and uses /noop in the file handling commands:
alias filetest {
var %ticks = $ticks
.fopen filetest $1-
if (!$ferr) {
while (!$feof) noop $fread(filetest)
}
.fclose filetest
echo -a File handling commands time taken: $calc($ticks - %ticks) ms.
return
:error
if (*command halted* iswm $error) {
close -@ @test
if ($fopen(filetest)) .fclose $v1
}
}
alias filtertest {
var %ticks = $ticks
filter -ff $1- NUL
echo -a Filter command time taken: $calc($ticks - %ticks) ms.
}
alias test {
var %file = $qt($scriptdir $+ 2007.07.fflog.txt)
filetest %file
filtertest %file
}
In this third test the file handling actually isn't that much slower than filter, but filter still takes the crown:
File handling commands time taken: 7031 ms.
Filter command time taken: 5125 ms.
File handling commands time taken: 7047 ms.
Filter command time taken: 5125 ms.
File handling commands time taken: 7031 ms.
Filter command time taken: 5141 ms.
File handling commands time taken: 7031 ms.
Filter command time taken: 5125 ms.
File handling commands time taken: 7031 ms.
Filter command time taken: 5109 ms.
I think the major benefit of /filter is actually that it's less code to write, not so much that it's so much speedier than using the file handling routines.