[Comparative performance] Methods of copying files : input to output

A

Alex Vinokur

Copying files : input to output
===============================

C/C++ Performance Tests
=======================
Using C/C++ Program Perfometer
http://sourceforge.net/projects/cpp-perfometer
http://alexvn.freeservers.com/s1/perfometer.html



Environment
-----------
Windows 2000 Professional
CYGWIN_NT-5.0 1.3.22(0.78/3/2)
Intel(R) Celeron(R) CPU 1.70 GHz
GNU gcc/g++ version 3.2 20020927 (prerelease)
Compilation : No optimization



#################################################
Stream I/O performance tests below are based
on the article "Stream I/O"
presented at http://www.glenmccl.com/strm_cmp.htm
by Glen McCluskey & Associates LLC
#################################################



===================== Methods of copying : BEGIN =====================

ifstream in_fs;
ofstream out_fs;

FILE* in_fp;
FILE* out_fp;

char ch;
int ich;



Method-1 : Functions getc() and putc()
-----------------------------------------------------
while ((ich = getc(in_fp)) != EOF) putc(ich, out_fp);
-----------------------------------------------------


Method-2 : Functions fgetc() and fputc()
-------------------------------------------------------
while ((ich = fgetc(in_fp)) != EOF) fputc(ich, out_fp);
-------------------------------------------------------


Method-3 : Operators >> and <<
---------------------------------
in_fs.unsetf(ios::skipws);
while (in_fs >> ch) out_fs << ch;
---------------------------------


Method-4 : Methods get() and put()
-------------------------------------
while (in_fs.get(ch)) out_fs.put(ch);
-------------------------------------


Method-5 : Methods sbumpc() and sputc()
------------------------------------------------------------------------
while ((ch = in_fs.rdbuf()->sbumpc()) != EOF) out_fs.rdbuf()->sputc(ch);
------------------------------------------------------------------------


Method-6 : Method sbumpc() and operator <<
-------------------------------
ch = in_fs.rdbuf()->sbumpc();
out_fs << ch;
while (ch != EOF)
{
out_fs << in_fs.rdbuf();
ch = in_fs.rdbuf()->sbumpc();
}
-------------------------------



===================== Methods of copying : END =======================



================ Performance tests : BEGIN ================



#==========================================================
# Comparison : copying files : input to output
#----------------------------------------------------------
# Resource Name : user time used (via rusage)
# Resource Cost Unit : milliseconds (unsigned long long)
# Resource State Unit : timeval
#==========================================================



Summary test results (Run-1)
============================
---------------------------------------------------------------
| | | User time used for |
| N | Method | file size |
| | |-----------------------|
| | | 100 | 1000 | 10000 |
|-------------------------------------------------------------|
| 1 | Functions getc() and putc() | 16 | 60 | 488 |
| 2 | Functions fgetc() and fputc() | 13 | 48 | 515 |
| 3 | Operators >> and << | 66 | 511 | 5080 |
| 4 | Methods get() and put() | 33 | 225 | 2356 |
| 5 | Methods sbumpc() and sputc() | 28 | 133 | 1560 |
| 6 | Method sbumpc() and operator << | 26 | 53 | 529 |
---------------------------------------------------------------
Raw Log : http://groups.google.com/[email protected]



Summary test results (Run-2)
============================
---------------------------------------------------------------
| | | User time used for |
| N | Method | file size |
| | |-----------------------|
| | | 100 | 1000 | 10000 |
|-------------------------------------------------------------|
| 1 | Functions getc() and putc() | 24 | 91 | 774 |
| 2 | Functions fgetc() and fputc() | 25 | 86 | 814 |
| 3 | Operators >> and << | 97 | 790 | 7913 |
| 4 | Methods get() and put() | 58 | 345 | 3393 |
| 5 | Methods sbumpc() and sputc() | 42 | 211 | 1881 |
| 6 | Method sbumpc() and operator << | 31 | 73 | 648 |
---------------------------------------------------------------
Raw Log : http://groups.google.com/[email protected]



================ Performance tests : END ==================


==============================================
Alex Vinokur
mailto:[email protected]
http://mathforum.org/library/view/10978.html
==============================================
 
I

Ivan Vecerina

| Method-6 : Method sbumpc() and operator <<
| ch = in_fs.rdbuf()->sbumpc();
| out_fs << ch;
| while (ch != EOF)
| {
| out_fs << in_fs.rdbuf();
| ch = in_fs.rdbuf()->sbumpc();
| }

Isn't this equivalent to just writing:
out_fs << in_fs.rdbuf();

My library doc says that this overload of << copies characters
from the source buffer until EOF is reached.

And yes, a C++ implementation should be able to provide an
optimal, specialized implementation of this function.
So it definitely should be able to outperform a character-by-
character copy using C files...


Regards,
Ivan
 
A

Alex Vinokur

Ivan Vecerina said:
| Method-6 : Method sbumpc() and operator <<
| ch = in_fs.rdbuf()->sbumpc();
| out_fs << ch;
| while (ch != EOF)
| {
| out_fs << in_fs.rdbuf();
| ch = in_fs.rdbuf()->sbumpc();
| }

Isn't this equivalent to just writing:
out_fs << in_fs.rdbuf();

My library doc says that this overload of << copies characters
from the source buffer until EOF is reached.
[snip]

Thanks.

Here are summary results of changed tests.



Copying files : input to output
===============================

C/C++ Performance Tests
=======================
Using C/C++ Program Perfometer
http://sourceforge.net/projects/cpp-perfometer
http://alexvn.freeservers.com/s1/perfometer.html



Environment
-----------
Windows 2000 Professional
CYGWIN_NT-5.0 1.3.22(0.78/3/2)
Intel(R) Celeron(R) CPU 1.70 GHz
GNU gcc/g++ version 3.2 20020927 (prerelease)
Compilation : No optimization



#################################################
Stream I/O performance tests below are based
on the article "Stream I/O"
presented at http://www.glenmccl.com/strm_cmp.htm
by Glen McCluskey & Associates LLC
#################################################



===================== Methods of copying : BEGIN =====================

ifstream in_fs;
ofstream out_fs;

FILE* in_fp;
FILE* out_fp;

char ch;
int ich;



Method C-1 : Functions getc() and putc()
-----------------------------------------------------
while ((ich = getc(in_fp)) != EOF) putc(ich, out_fp);
-----------------------------------------------------


Method C-2 : Functions fgetc() and fputc()
-------------------------------------------------------
while ((ich = fgetc(in_fp)) != EOF) fputc(ich, out_fp);
-------------------------------------------------------


Method CPP-1 : Operators >> and <<
---------------------------------
in_fs.unsetf(ios::skipws);
while (in_fs >> ch) out_fs << ch;
---------------------------------


Method CPP-2 : Methods get() and put()
-------------------------------------
while (in_fs.get(ch)) out_fs.put(ch);
-------------------------------------


Method CPP-3 : Methods sbumpc() and sputc()
------------------------------------------------------------------------
while ((ch = in_fs.rdbuf()->sbumpc()) != EOF) out_fs.rdbuf()->sputc(ch);
------------------------------------------------------------------------


Method CPP-4 : Method sbumpc() and operator <<
-------------------------------
ch = in_fs.rdbuf()->sbumpc();
out_fs << ch;
while (ch != EOF)
{
out_fs << in_fs.rdbuf();
ch = in_fs.rdbuf()->sbumpc();
}
-------------------------------


Method CPP-5 : Method rdbuf() and operator <<
------------------------
out_fs << in_fs.rdbuf();
------------------------



===================== Methods of copying : END =======================




================ Performance tests : BEGIN ================



#==========================================================
# Comparison : copying files : input to output
#----------------------------------------------------------
# Resource Name : user time used (via rusage)
# Resource Cost Unit : milliseconds (unsigned long long)
# Resource State Unit : timeval
#==========================================================



Summary test results (Run-3)
============================
--------------------------------------------------------------------
| | | User time used for |
| No. | Method | file size |
| | |-----------------------|
| | | 100 | 1000 | 10000 |
|------------------------------------------------------------------|
| C-1 | Functions getc() and putc() | 60 | 177 | 1625 |
| C-2 | Functions fgetc() and fputc() | 53 | 186 | 1749 |
| | | | | |
| CPP-1 | Operators >> and << | 226 | 1662 | 15984 |
| CPP-2 | Methods get() and put() | 136 | 796 | 7562 |
| CPP-3 | Methods sbumpc() and sputc() | 88 | 448 | 3930 |
| CPP-4 | Method sbumpc() and operator << | 65 | 155 | 1483 |
| CPP-5 | Method rdbuf() and operator << | 78 | 173 | 1440 |
--------------------------------------------------------------------
Raw Log : http://groups.google.com/[email protected]




Summary test results (Run-4)
============================
--------------------------------------------------------------------
| | | User time used for |
| No. | Method | file size |
| | |-----------------------|
| | | 100 | 1000 | 10000 |
|------------------------------------------------------------------|
| C-1 | Functions getc() and putc() | 40 | 103 | 1342 |
| C-2 | Functions fgetc() and fputc() | 64 | 113 | 1265 |
| | | | | |
| CPP-1 | Operators >> and << | 179 | 1225 | 14768 |
| CPP-2 | Methods get() and put() | 96 | 614 | 7324 |
| CPP-3 | Methods sbumpc() and sputc() | 76 | 350 | 3741 |
| CPP-4 | Method sbumpc() and operator << | 57 | 130 | 1469 |
| CPP-5 | Method rdbuf() and operator << | 70 | 153 | 1432 |
--------------------------------------------------------------------
Raw Log : http://groups.google.com/[email protected]



================ Performance tests : END ==================


==============================================
Alex Vinokur
mailto:[email protected]
http://mathforum.org/library/view/10978.html
==============================================
 
J

Jerry Coffin

[ ... ]
Environment
-----------
Windows 2000 Professional
CYGWIN_NT-5.0 1.3.22(0.78/3/2)
Intel(R) Celeron(R) CPU 1.70 GHz
GNU gcc/g++ version 3.2 20020927 (prerelease)
Compilation : No optimization

This seems to me to render the results nearly meaningless. IIRC, gcc
3.2 is now officially obsolescent (i.e. 3.3 has been released) and
you're not even working with the released version of it, but apparently
with a pre-release. To make matters worse, you're turning off all
optimization.

IOW, while your results are interesting, it seems somewhat doubtful to
me whether they reflect much about what anybody is likely to encounter
in real use. It _may_ be that these parts of the library have remained
close enough to constant that they reflect something about other
versions of cygwin, but without some checking, I have some doubt even
about that. For almost anything else, the relation between the
benchmark and reality seems even more tenuous.

Note that I'm not saying there is no relationship or anything like it:
the results you've given _may_ be reasonably close to constant across
many compilers, OSes, etc., but without (at least) considerably more
testing, it's almost impossible to say one way or another.
 
A

Alex Vinokur

Jerry Coffin said:
[ ... ]
Environment
-----------
Windows 2000 Professional
CYGWIN_NT-5.0 1.3.22(0.78/3/2)
Intel(R) Celeron(R) CPU 1.70 GHz
GNU gcc/g++ version 3.2 20020927 (prerelease)
Compilation : No optimization

This seems to me to render the results nearly meaningless. IIRC, gcc
3.2 is now officially obsolescent (i.e. 3.3 has been released) and
you're not even working with the released version of it, but apparently
with a pre-release.
About released and pre-released gcc version on Cygwin see http://article.gmane.org/gmane.os.cygwin/29223
To make matters worse, you're turning off all optimization.
1. I think also that (behavior of original program) might/should be intersest to software designers.
2. Comparative performance tests may be carried out by the concerned designer for various conditions :
* gcc (No optimitahation, O1, O2, O3),
* Another compiler,
* Another OS.

[snip]

=====================================
Alex Vinokur
mailto:[email protected]
http://mathforum.org/library/view/10978.html
=====================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,967
Messages
2,570,148
Members
46,694
Latest member
LetaCadwal

Latest Threads

Top