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

Discussion in 'C++' started by Alex Vinokur, Aug 22, 2003.

  1. Alex Vinokur

    Alex Vinokur Guest

    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=bi46rc$4qd15$-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=bi47o4$46vpv$-berlin.de



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


    ==============================================
    Alex Vinokur
    mailto:
    http://mathforum.org/library/view/10978.html
    ==============================================
     
    Alex Vinokur, Aug 22, 2003
    #1
    1. Advertising

  2. "Alex Vinokur" <> wrote in message
    news:bi57iv$550iv$-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
     
    Ivan Vecerina, Aug 22, 2003
    #2
    1. Advertising

  3. Alex Vinokur

    Alex Vinokur Guest

    "Ivan Vecerina" <> wrote in message news:3f464573$...
    > "Alex Vinokur" <> wrote in message
    > news:bi57iv$550iv$-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=bi741f$6088c$-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=bi742a$5qau1$-berlin.de



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


    ==============================================
    Alex Vinokur
    mailto:
    http://mathforum.org/library/view/10978.html
    ==============================================
     
    Alex Vinokur, Aug 23, 2003
    #3
  4. Alex Vinokur

    Jerry Coffin Guest

    In article <bi57iv$550iv$-berlin.de>,
    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.
     
    Jerry Coffin, Aug 24, 2003
    #4
  5. Alex Vinokur

    Alex Vinokur Guest

    "Jerry Coffin" <> wrote in message news:...
    > In article <bi57iv$550iv$-berlin.de>,
    > 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:
    http://mathforum.org/library/view/10978.html
    =====================================
     
    Alex Vinokur, Aug 25, 2003
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex Vinokur
    Replies:
    8
    Views:
    358
    Florian Weimer
    Nov 23, 2003
  2. Alex Vinokur
    Replies:
    0
    Views:
    524
    Alex Vinokur
    Aug 29, 2004
  3. Alex Vinokur
    Replies:
    6
    Views:
    1,070
    Alex Vinokur
    Aug 30, 2003
  4. toton
    Replies:
    6
    Views:
    343
    Greg Comeau
    Oct 25, 2006
  5. Ilias Lazaridis
    Replies:
    2
    Views:
    128
    Ilias Lazaridis
    Apr 24, 2005
Loading...

Share This Page