Next | Making Programs Faster | 106 |
% wc myin.dat
1568 5707 44808 myin.dat
% perl -d:SmallProf copy1.pl
% wc myin.dat
1466 5215 40357 myin.dat
% cat smallprof.out
================ SmallProf version 0.9 ================
Profile of ./copy1.pl Page 1
=================================================================
count wall tm cpu time line
0 0.000000 0.000000 1:#!/usr/bin/perl
0 0.000000 0.000000 2:
1 0.000186 0.000000 3:open IN, "myin.dat" or "die: $!";
1 0.000196 0.000000 4:open OUT, ">myout.dat" or "die: $!";
1570 0.013959 0.270000 5:while (<IN>)
1569 0.015762 0.270000 6: { print OUT $_ unless (/^#/);
0 0.000000 0.000000 7: }
1 0.000239 0.000000 8:close OUT;
1 0.000054 0.000000 9:close IN;
1 0.000304 0.000000 10:rename "myout.dat", "myin.dat";
Lines 5 and 6, which copy the file, consume 96.8% of the total run time
And so close to 100% of the CPU time that the difference is not detectable
But this opens two files and does a rename. I suspect this
won't be very efficient.
Is there a better way? Thanks for any
advice.
My advice: You are worrying about the wrong thing
Next | Copyright © 2003 M. J. Dominus |