473,387 Members | 1,603 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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



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/groups?selm....uni-berlin.de

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/groups?selm....uni-berlin.de

================ Performance tests : END ==================
==============================================
Alex Vinokur
mailto:al****@connect.to
http://mathforum.org/library/view/10978.html
==============================================

Jul 19 '05 #1
4 2933
"Alex Vinokur" <al****@bigfoot.com> wrote in message
news:bi************@ID-79865.news.uni-berlin.de...
| 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
--
http://www.post1.com/~ivec
Jul 19 '05 #2

"Ivan Vecerina" <iv**@myrealbox.com> wrote in message news:3f********@news.swissonline.ch...
"Alex Vinokur" <al****@bigfoot.com> wrote in message
news:bi************@ID-79865.news.uni-berlin.de...
| 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/groups?selm....uni-berlin.de


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/groups?selm....uni-berlin.de

================ Performance tests : END ==================
==============================================
Alex Vinokur
mailto:al****@connect.to
http://mathforum.org/library/view/10978.html
==============================================


Jul 19 '05 #3
In article <bi************@ID-79865.news.uni-berlin.de>,
al****@bigfoot.com says...

[ ... ]
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.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jul 19 '05 #4

"Jerry Coffin" <jc*****@taeus.com> wrote in message news:MP************************@news.west.earthlin k.net...
In article <bi************@ID-79865.news.uni-berlin.de>,
al****@bigfoot.com says...

[ ... ]
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:al****@connect.to
http://mathforum.org/library/view/10978.html
=====================================
Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Alex Vinokur | last post by:
Various forms of argument passing ================================= C/C++ Performance Tests ======================= Using C/C++ Program Perfometer...
0
by: Alex Vinokur | last post by:
=================================== ------------- Sorting ------------- Comparative performance measurement =================================== Testsuite : Comparing Function Objects to...
6
by: Jason Heyes | last post by:
I am starting to worry about the performance of formatted read/write operations on data-redundant objects in my program.What can I do to improve this performance should it become an issue? ...
51
by: Jojo | last post by:
Is there any way to get to the left-hand side of an operator? Consider the following (this is not meant to be perfect code, just an example of the problem): class Matrix { public: int data;...
6
by: Alex Vinokur | last post by:
Here are results of comparative performance tests carried out using the same compiler (gcc 3.2) in different environments (CYGWIN, MINGW, DJGPP) on Windows 2000 Professional. The following...
6
by: seeIT | last post by:
In a client application a simple webservice (add/multiply) was added to solution panel but proxy methods do not appear. WSDL description in solution panel follows: <?xml version="1.0"...
2
by: Madhusudhanan Chandrasekaran | last post by:
Hi: This question is not directed "entirely" at python only. But since I want to know how to do it in python, I am posting here. I am constructing a huge matrix (m x n), whose columns n are...
7
by: Michael D. Ober | last post by:
When calling Enqueue, the internal array may need to be reallocated. My question is by how much? In the old MFC array classes, you could tell MFC how many additional elements to add to the array...
0
by: Ketchup | last post by:
Hello everyone, I am writing a utility. Part of its function is to do a block-mode copy of files and generate MD5 / SHA1 hashes on the fly. The functionality is similar to that of the Unix...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.