473,224 Members | 1,965 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,224 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 2921
"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: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.