[Comparative performance] Various forms of argument passing

Discussion in 'C++' started by Alex Vinokur, Sep 1, 2003.

  1. Alex Vinokur

    Alex Vinokur Guest

    Various forms of argument passing
    =================================

    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




    ===================== Forms of argument passing : BEGIN =====================

    ------ Tested functions ------

    void foo_char_ptr (char* ) {} // via char ptr
    void foo_char_array (char[] ) {} // via char array

    void foo_string_ref (const string& ) {} // via ref to string
    void foo_string_value (string ) {} // via string value

    void foo_vector_ref (const vector<char>& ) {} // via ref to vector
    void foo_vector_value (vector<char> ) {} // via vector value

    void foo_list_ref (const list<char>& ) {} // via ref to list
    void foo_list_value (list<char> ) {} // via list value

    void foo_set_ref (const set<size_t>& ) {} // via ref to set
    void foo_set_value (set<size_t> ) {} // via set value

    void foo_map_ref (const map<size_t, int>& ) {} // via ref to map
    void foo_map_value (map<size_t, int> ) {} // via map value


    ------ Data (fragments) ------

    const size_t data_size = <data size>;

    string str; // str.size() == data_size
    vector<char> vct; // vct.size() == data_size
    list<char> lst; // lst.size() == data_size
    set<size_t> st; // st.size() == data_size
    map<size_t,int> mp; // mp.size() == data_size
    char* pcstr; // strlen (pcstr) == data_size
    char acstr [data_size + 1]; // strlen (acstr) == data_size

    Note. acstr is used only with GNU compiler


    ------ Calling tested functions ------

    foo_char_ptr (pcstr); // char ptr via char ptr
    foo_char_array (pcstr); // char ptr via char array
    foo_char_ptr (acstr); // char array via char ptr
    foo_char_array (acstr); // char array via char array

    foo_string_ref (str); // string via ref to string
    foo_string_value (str); // string via string value
    foo_string_ref (pcstr); // char ptr via ref to string
    foo_string_value (pcstr); // char ptr via string value
    foo_string_ref (acstr); // char array via ref to string
    foo_string_value (acstr); // char array via string value

    foo_vector_ref (vct); // vector<char> via ref to vector
    foo_vector_value (vct); // vector<char> via vector value
    foo_list_ref (lst); // list<char> via ref to list
    foo_list_value (lst); // list<char> via list value
    foo_set_ref (st); // set<size_t> via ref to set
    foo_set_value (st); // set<size_t> via set value
    foo_map_ref (mp); // map<size_t, int> via ref to map
    foo_map_value (mp); // map<size_t, int> via map value


    ===================== Forms of argument passing : END =======================



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



    #==========================================================
    # Comparison : various forms of argument passing
    #----------------------------------------------------------
    # Resource Name : user time used (via rusage)
    # Resource Cost Unit : milliseconds (unsigned long long)
    # per 10000000 calls (repetitions)
    # Resource State Unit : timeval
    #==========================================================



    Summary test results
    ====================
    ----------------------------------------------------------------------------
    | | | User time used for |
    | N | Form of argument passing | data size |
    | | |-----------------------------|
    | | | 10 | 100 | 1000 |
    |--------------------------------------------------------------------------|
    | 1 | char ptr via char ptr | 80 | 80 | 70 |
    | 2 | char ptr via char array | 70 | 70 | 70 |
    | 3 | char array via char ptr | 70 | 70 | 80 |
    | 4 | char array via char array | 80 | 69 | 70 |
    | | | | | |
    | 5 | string via ref to string | 70 | 70 | 80 |
    | 6 | string via string value | 4000 | 4000 | 4200 |
    | 7 | char ptr via ref to string | 8500 | 15000 | 93300 |
    | 8 | char ptr via string value | 9000 | 15000 | 90200 |
    | 9 | char array via ref to string | 8800 | 15100 | 89900 |
    | 10 | char array via string value | 8900 | 15000 | 90100 |
    | | | | | |
    | 11 | vector<char> via ref to vector | 70 | 70 | 70 |
    | 12 | vector<char> via vector value | 10900 | 12000 | 38500 |
    | 13 | list<char> via ref to list | 80 | 80 | 70 |
    | 14 | list<char> via list value | 41000 | 361000 | 3563000 |
    | 15 | set<size_t> via ref to set | 70 | 70 | 79 |
    | 16 | set<size_t> via set value | 43000 | 400000 | 4199000 |
    | 17 | map<size_t, int> via ref to map | 71 | 81 | 71 |
    | 18 | map<size_t, int> via map value | 42000 | 373000 | 4207000 |
    ----------------------------------------------------------------------------
    Comment-question. 'string via string value' doesn't depend on data size (?)



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


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

  2. "Alex Vinokur" <> writes:

    > Comment-question. 'string via string value' doesn't depend on
    > data size (?)


    Some implementations of std::string use copy-on-write semantics
    internally.
     
    Florian Weimer, Sep 1, 2003
    #2
    1. Advertising

  3. Alex Vinokur

    Jack Klein Guest

    On Mon, 1 Sep 2003 13:57:29 +0300, "Alex Vinokur" <>
    wrote in comp.lang.c++:

    >
    > Various forms of argument passing
    > =================================
    >
    > C/C++ Performance Tests
    > =======================
    > Using C/C++ Program Perfometer
    > http://sourceforge.net/projects/cpp-perfometer
    > http://alexvn.freeservers.com/s1/perfometer.html


    [snip]

    This is probably very much on-topic in comp.software.measurement, but
    it is very much OFF-TOPIC in comp.lang.c. Please STOP cross-posting
    this stuff to comp.lang.c.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c /faq
     
    Jack Klein, Sep 1, 2003
    #3
  4. Alex Vinokur

    Alex Vinokur Guest

    "Florian Weimer" <> wrote in message news:...
    > "Alex Vinokur" <> writes:
    >
    > > Comment-question. 'string via string value' doesn't depend on
    > > data size (?)

    >
    > Some implementations of std::string use copy-on-write semantics
    > internally.


    Does it have to do with copy-initialization?

    =====================================
    Alex Vinokur
    mailto:
    http://mathforum.org/library/view/10978.html
    =====================================
     
    Alex Vinokur, Sep 2, 2003
    #4
  5. Alex Vinokur

    Alex Vinokur Guest

    "Jack Klein" <> wrote in message news:eek:...
    > On Mon, 1 Sep 2003 13:57:29 +0300, "Alex Vinokur" <>
    > wrote in comp.lang.c++:
    >
    > >
    > > Various forms of argument passing
    > > =================================
    > >
    > > C/C++ Performance Tests
    > > =======================
    > > Using C/C++ Program Perfometer
    > > http://sourceforge.net/projects/cpp-perfometer
    > > http://alexvn.freeservers.com/s1/perfometer.html

    >
    > [snip]
    >
    > This is probably very much on-topic in comp.software.measurement, but
    > it is very much OFF-TOPIC in comp.lang.c. Please STOP cross-posting
    > this stuff to comp.lang.c.
    >

    [snip]

    The message named "[Comparative performance] Various forms of argument passing" has never been posted to news:comp.lang.c.

    =====================================
    Alex Vinokur
    mailto:
    http://mathforum.org/library/view/10978.html
    =====================================
     
    Alex Vinokur, Sep 2, 2003
    #5
  6. Alex Vinokur

    Mon Guest

    Alex Vinokur <> wrote in message
    news:biv8u5$dj6cf$-berlin.de...
    >
    > Various forms of argument passing
    > =================================
    >
    > 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
    >
    >
    >
    >
    > ===================== Forms of argument passing : BEGIN

    =====================
    >
    > ------ Tested functions ------
    >
    > void foo_char_ptr (char* ) {} // via char ptr
    > void foo_char_array (char[] ) {} // via char array
    >
    > void foo_string_ref (const string& ) {} // via ref to

    string
    > void foo_string_value (string ) {} // via string value
    >
    > void foo_vector_ref (const vector<char>& ) {} // via ref to

    vector
    > void foo_vector_value (vector<char> ) {} // via vector value
    >
    > void foo_list_ref (const list<char>& ) {} // via ref to list
    > void foo_list_value (list<char> ) {} // via list value
    >
    > void foo_set_ref (const set<size_t>& ) {} // via ref to set
    > void foo_set_value (set<size_t> ) {} // via set value
    >
    > void foo_map_ref (const map<size_t, int>& ) {} // via ref to map
    > void foo_map_value (map<size_t, int> ) {} // via map value
    >
    >
    > ------ Data (fragments) ------
    >
    > const size_t data_size = <data size>;
    >
    > string str; // str.size() == data_size
    > vector<char> vct; // vct.size() == data_size
    > list<char> lst; // lst.size() == data_size
    > set<size_t> st; // st.size() == data_size
    > map<size_t,int> mp; // mp.size() == data_size
    > char* pcstr; // strlen (pcstr) == data_size
    > char acstr [data_size + 1]; // strlen (acstr) == data_size
    >
    > Note. acstr is used only with GNU compiler
    >
    >
    > ------ Calling tested functions ------
    >
    > foo_char_ptr (pcstr); // char ptr via char ptr
    > foo_char_array (pcstr); // char ptr via char array
    > foo_char_ptr (acstr); // char array via char ptr
    > foo_char_array (acstr); // char array via char array
    >
    > foo_string_ref (str); // string via ref to string
    > foo_string_value (str); // string via string value
    > foo_string_ref (pcstr); // char ptr via ref to string
    > foo_string_value (pcstr); // char ptr via string value
    > foo_string_ref (acstr); // char array via ref to string
    > foo_string_value (acstr); // char array via string value
    >
    > foo_vector_ref (vct); // vector<char> via ref to vector
    > foo_vector_value (vct); // vector<char> via vector value
    > foo_list_ref (lst); // list<char> via ref to list
    > foo_list_value (lst); // list<char> via list value
    > foo_set_ref (st); // set<size_t> via ref to set
    > foo_set_value (st); // set<size_t> via set value
    > foo_map_ref (mp); // map<size_t, int> via ref to map
    > foo_map_value (mp); // map<size_t, int> via map value
    >
    >
    > ===================== Forms of argument passing : END

    =======================
    >
    >
    >
    > ================ Performance tests : BEGIN ================
    >
    >
    >
    > #==========================================================
    > # Comparison : various forms of argument passing
    > #----------------------------------------------------------
    > # Resource Name : user time used (via rusage)
    > # Resource Cost Unit : milliseconds (unsigned long long)
    > # per 10000000 calls (repetitions)
    > # Resource State Unit : timeval
    > #==========================================================
    >
    >
    >
    > Summary test results
    > ====================
    > -----------------------------------------------------------------------

    -----
    > | | | User time used for

    |
    > | N | Form of argument passing | data size

    |
    > | |

    |-----------------------------|
    > | | | 10 | 100 |

    1000 |
    >

    |--------------------------------------------------------------------------|
    > | 1 | char ptr via char ptr | 80 | 80 |

    70 |
    > | 2 | char ptr via char array | 70 | 70 |

    70 |
    > | 3 | char array via char ptr | 70 | 70 |

    80 |
    > | 4 | char array via char array | 80 | 69 |

    70 |
    > | | | | |

    |
    > | 5 | string via ref to string | 70 | 70 |

    80 |
    > | 6 | string via string value | 4000 | 4000 |

    4200 |
    > | 7 | char ptr via ref to string | 8500 | 15000 |

    93300 |
    > | 8 | char ptr via string value | 9000 | 15000 |

    90200 |
    > | 9 | char array via ref to string | 8800 | 15100 |

    89900 |
    > | 10 | char array via string value | 8900 | 15000 |

    90100 |
    > | | | | |

    |
    > | 11 | vector<char> via ref to vector | 70 | 70 |

    70 |
    > | 12 | vector<char> via vector value | 10900 | 12000 |

    38500 |
    > | 13 | list<char> via ref to list | 80 | 80 |

    70 |
    > | 14 | list<char> via list value | 41000 | 361000 |

    3563000 |
    > | 15 | set<size_t> via ref to set | 70 | 70 |

    79 |
    > | 16 | set<size_t> via set value | 43000 | 400000 |

    4199000 |
    > | 17 | map<size_t, int> via ref to map | 71 | 81 |

    71 |
    > | 18 | map<size_t, int> via map value | 42000 | 373000 |

    4207000 |
    > -----------------------------------------------------------------------

    -----
    > Comment-question. 'string via string value' doesn't depend on data

    size (?)
    >
    >
    >
    > ================ Performance tests : END ==================
    >
    >
    > ==============================================
    > Alex Vinokur
    > mailto:
    > http://mathforum.org/library/view/10978.html
    > ==============================================
    >
    >
    >
    >
    >
     
    Mon, Sep 2, 2003
    #6
  7. Alex Vinokur

    Mon Guest

    Can the posters to this thread please confine themselves to their own
    newsgroup & stop cross-posting
    Alex Vinokur <> wrote in message
    news:biv8u5$dj6cf$-berlin.de...
    >
    > Various forms of argument passing
    > =================================
    >
    > 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
    >
    >
    >
    >
    > ===================== Forms of argument passing : BEGIN

    =====================
    >
    > ------ Tested functions ------
    >
    > void foo_char_ptr (char* ) {} // via char ptr
    > void foo_char_array (char[] ) {} // via char array
    >
    > void foo_string_ref (const string& ) {} // via ref to

    string
    > void foo_string_value (string ) {} // via string value
    >
    > void foo_vector_ref (const vector<char>& ) {} // via ref to

    vector
    > void foo_vector_value (vector<char> ) {} // via vector value
    >
    > void foo_list_ref (const list<char>& ) {} // via ref to list
    > void foo_list_value (list<char> ) {} // via list value
    >
    > void foo_set_ref (const set<size_t>& ) {} // via ref to set
    > void foo_set_value (set<size_t> ) {} // via set value
    >
    > void foo_map_ref (const map<size_t, int>& ) {} // via ref to map
    > void foo_map_value (map<size_t, int> ) {} // via map value
    >
    >
    > ------ Data (fragments) ------
    >
    > const size_t data_size = <data size>;
    >
    > string str; // str.size() == data_size
    > vector<char> vct; // vct.size() == data_size
    > list<char> lst; // lst.size() == data_size
    > set<size_t> st; // st.size() == data_size
    > map<size_t,int> mp; // mp.size() == data_size
    > char* pcstr; // strlen (pcstr) == data_size
    > char acstr [data_size + 1]; // strlen (acstr) == data_size
    >
    > Note. acstr is used only with GNU compiler
    >
    >
    > ------ Calling tested functions ------
    >
    > foo_char_ptr (pcstr); // char ptr via char ptr
    > foo_char_array (pcstr); // char ptr via char array
    > foo_char_ptr (acstr); // char array via char ptr
    > foo_char_array (acstr); // char array via char array
    >
    > foo_string_ref (str); // string via ref to string
    > foo_string_value (str); // string via string value
    > foo_string_ref (pcstr); // char ptr via ref to string
    > foo_string_value (pcstr); // char ptr via string value
    > foo_string_ref (acstr); // char array via ref to string
    > foo_string_value (acstr); // char array via string value
    >
    > foo_vector_ref (vct); // vector<char> via ref to vector
    > foo_vector_value (vct); // vector<char> via vector value
    > foo_list_ref (lst); // list<char> via ref to list
    > foo_list_value (lst); // list<char> via list value
    > foo_set_ref (st); // set<size_t> via ref to set
    > foo_set_value (st); // set<size_t> via set value
    > foo_map_ref (mp); // map<size_t, int> via ref to map
    > foo_map_value (mp); // map<size_t, int> via map value
    >
    >
    > ===================== Forms of argument passing : END

    =======================
    >
    >
    >
    > ================ Performance tests : BEGIN ================
    >
    >
    >
    > #==========================================================
    > # Comparison : various forms of argument passing
    > #----------------------------------------------------------
    > # Resource Name : user time used (via rusage)
    > # Resource Cost Unit : milliseconds (unsigned long long)
    > # per 10000000 calls (repetitions)
    > # Resource State Unit : timeval
    > #==========================================================
    >
    >
    >
    > Summary test results
    > ====================
    > -----------------------------------------------------------------------

    -----
    > | | | User time used for

    |
    > | N | Form of argument passing | data size

    |
    > | |

    |-----------------------------|
    > | | | 10 | 100 |

    1000 |
    >

    |--------------------------------------------------------------------------|
    > | 1 | char ptr via char ptr | 80 | 80 |

    70 |
    > | 2 | char ptr via char array | 70 | 70 |

    70 |
    > | 3 | char array via char ptr | 70 | 70 |

    80 |
    > | 4 | char array via char array | 80 | 69 |

    70 |
    > | | | | |

    |
    > | 5 | string via ref to string | 70 | 70 |

    80 |
    > | 6 | string via string value | 4000 | 4000 |

    4200 |
    > | 7 | char ptr via ref to string | 8500 | 15000 |

    93300 |
    > | 8 | char ptr via string value | 9000 | 15000 |

    90200 |
    > | 9 | char array via ref to string | 8800 | 15100 |

    89900 |
    > | 10 | char array via string value | 8900 | 15000 |

    90100 |
    > | | | | |

    |
    > | 11 | vector<char> via ref to vector | 70 | 70 |

    70 |
    > | 12 | vector<char> via vector value | 10900 | 12000 |

    38500 |
    > | 13 | list<char> via ref to list | 80 | 80 |

    70 |
    > | 14 | list<char> via list value | 41000 | 361000 |

    3563000 |
    > | 15 | set<size_t> via ref to set | 70 | 70 |

    79 |
    > | 16 | set<size_t> via set value | 43000 | 400000 |

    4199000 |
    > | 17 | map<size_t, int> via ref to map | 71 | 81 |

    71 |
    > | 18 | map<size_t, int> via map value | 42000 | 373000 |

    4207000 |
    > -----------------------------------------------------------------------

    -----
    > Comment-question. 'string via string value' doesn't depend on data

    size (?)
    >
    >
    >
    > ================ Performance tests : END ==================
    >
    >
    > ==============================================
    > Alex Vinokur
    > mailto:
    > http://mathforum.org/library/view/10978.html
    > ==============================================
    >
    >
    >
    >
    >
     
    Mon, Sep 2, 2003
    #7
  8. Alex Vinokur

    llewelly Guest

    "Alex Vinokur" <> writes:

    > "Florian Weimer" <> wrote in message news:...
    >> "Alex Vinokur" <> writes:
    >>
    >> > Comment-question. 'string via string value' doesn't depend on
    >> > data size (?)

    >>
    >> Some implementations of std::string use copy-on-write semantics
    >> internally.

    >
    > Does it have to do with copy-initialization?


    Yes.
     
    llewelly, Sep 2, 2003
    #8
  9. "Alex Vinokur" <> writes:

    > > > Comment-question. 'string via string value' doesn't depend on
    > > > data size (?)

    > >
    > > Some implementations of std::string use copy-on-write semantics
    > > internally.

    >
    > Does it have to do with copy-initialization?


    I'd think so. You just have to copy a few pointers and increment a
    reference count in the copy constructor.
     
    Florian Weimer, Nov 23, 2003
    #9
    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:
    4
    Views:
    373
    Alex Vinokur
    Aug 25, 2003
  2. Alex Vinokur
    Replies:
    0
    Views:
    524
    Alex Vinokur
    Aug 29, 2004
  3. Alex Vinokur
    Replies:
    6
    Views:
    1,072
    Alex Vinokur
    Aug 30, 2003
  4. toton
    Replies:
    6
    Views:
    344
    Greg Comeau
    Oct 25, 2006
  5. Ilias Lazaridis
    Replies:
    2
    Views:
    128
    Ilias Lazaridis
    Apr 24, 2005
Loading...

Share This Page