[LC++]file copying
Paul Gearon
pag at pisoftware.com
Fri Jan 30 09:23:01 UTC 2004
Jan Pfeifer wrote:
> i thought about this, but then in one test i did, i copied 10000 times a
> small file that would fit entirely in the buffer I allocated and it was
> still 1.5 times slower than /bin/cp ...
>
> do you understand in this case why the difference ?
A couple of options come to mind, but I'll confess I'm surprised at the
time difference. Are you absolutely sure you're not seeing the cache
come into effect here? The first time you do any kind of copy then that
part of the filesystem will be sitting in memory and all subsequent
reads will be from RAM instead of the disk. All writes (especially for
small buffers) will return immediately and be scheduled for flushing to
disk at a later time. It's VERY hard to avoid these efficiencies for
the purpose of benchmarking!
Assuming you've taken these things into account... what optimisation are
you using? The code that a compiler builds can make a significant
difference to execution time.
Also, if you're comparing your code to cp for copying a small file then
I'm guessing that you're executing the program once for each copy. If
that's the case then the executable file format may also be having an
effect. Is the executable stripped? Is it ELF or a.out (probably ELF,
but since you have a problem here it's worth asking)? Are your
functions inlined, etc? Try lots of options here.
There are all kinds of things that could be making your code run slower
than cp. Normally you'd only worry about this if your code is very slow
and you've profiled it to demonstrate that this is a particular concern
for you. However, if it's really bothering you then try playing with
various optimisations and executable file formats.
If you want to isolate the file i/o differences between your code and cp
then try comparing them when copying very large files.
--
Regards,
Paul Gearon
Software Engineer Telephone: +61 7 3876 2188
Plugged In Software Fax: +61 7 3876 4899
http://www.PIsoftware.com PGP Key available via finger
Catapultam habeo. Nisi pecuniam omnem mihi dabis, ad caput tuum saxum
immane mittam.
(Translation from latin: "I have a catapult. Give me all the money,
or I will fling an enormous rock at your head.")
More information about the tuxCPProgramming
mailing list