To: bwk@bell-labs.com, cvanwyk@drew.edu cc: mjd@plover.com Subject: Trials of Timing Organization: Plover Systems Date: Fri, 21 Nov 1997 21:37:40 -0500 From: Mark-Jason Dominus I was a little puzzled by one of your sample programs. In the section on `file copying', you said: The first task is to copy input to output, uninterpreted and unexamined... But the Perl program you show does not do this. It says: while (<>) { chop; print $_; } The `chop' here removes the trailing newline from each line of the input; in this program is it not only superfluous but also incorrect, since the program while (<>) { print $_; } is what you want. This is worrisome. Is there code here that isn't shown? I suspect so, that you translated { print } with `a2p', and omitted the code that preceded the loop. Is this so? If not, I wonder whether any of the other programs generated incorrect output that you didn't notice. On my system, the correct (chopless) version ran about 25% faster than the incorrect version. I tested it on an input Bible of: % wc /tmp/bible 99465 820797 4330159 /tmp/bible I also found your 2x speedup here very surprising. When I modified the program to read the input in one chunk instead of in lines, it ran about six times faster. I was also puzzled by your reliance on `a2p'. Although nobody would expect you to hand-tune the test programs for performance, relying on an automatic machine translation from another language seems like a bad idea, and likely to skew the results. I don't think, for example, that you would have considered benchmarking C code that had been obtained from `awk2c'. a2p was not necessarily designed to produce speedy code, but rather code that would be compatible with awk. I am not too familiar with a2p, but I notice for example that the a2p translation of { print } performs some argument parsing, and needlessly removes the trailing newline character from each input line with `chop' and then implicitly replaces it again. Should you wish to investigate Perl further, I would be happy to assist you in preparing more representative Perl programs for your various tasks. Mark-Jason Dominus mjd@plover.com