By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,363 Members | 2,961 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,363 IT Pros & Developers. It's quick & easy.

[Comparative performance] Various forms of argument passing

P: n/a

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:al****@connect.to
http://mathforum.org/library/view/10978.html
==============================================

Jul 19 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
"Alex Vinokur" <al****@bigfoot.com> writes:
Comment-question. 'string via string value' doesn't depend on
data size (?)


Some implementations of std::string use copy-on-write semantics
internally.
Jul 19 '05 #2

P: n/a
On Mon, 1 Sep 2003 13:57:29 +0300, "Alex Vinokur" <al****@bigfoot.com>
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
Jul 19 '05 #3

P: n/a

"Florian Weimer" <fw@deneb.enyo.de> wrote in message news:87************@deneb.enyo.de...
"Alex Vinokur" <al****@bigfoot.com> 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:al****@connect.to
http://mathforum.org/library/view/10978.html
=====================================
Jul 19 '05 #4

P: n/a

"Jack Klein" <ja*******@spamcop.net> wrote in message news:o1********************************@4ax.com...
On Mon, 1 Sep 2003 13:57:29 +0300, "Alex Vinokur" <al****@bigfoot.com>
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:al****@connect.to
http://mathforum.org/library/view/10978.html
=====================================
Jul 19 '05 #5

P: n/a
Mon

Alex Vinokur <al****@bigfoot.com> wrote in message
news:bi************@ID-79865.news.uni-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:al****@connect.to
http://mathforum.org/library/view/10978.html
==============================================


Jul 19 '05 #6

P: n/a
Mon
Can the posters to this thread please confine themselves to their own
newsgroup & stop cross-posting
Alex Vinokur <al****@bigfoot.com> wrote in message
news:bi************@ID-79865.news.uni-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:al****@connect.to
http://mathforum.org/library/view/10978.html
==============================================


Jul 19 '05 #7

P: n/a
"Alex Vinokur" <al****@bigfoot.com> writes:
"Florian Weimer" <fw@deneb.enyo.de> wrote in message news:87************@deneb.enyo.de...
"Alex Vinokur" <al****@bigfoot.com> 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.
Jul 19 '05 #8

P: n/a
"Alex Vinokur" <al****@bigfoot.com> 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.
Jul 22 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.