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
==============================================
===============================
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
==============================================