C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[Comparative performance] Various forms of argument passing

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Alex Vinokur
Guest





PostPosted: Mon Sep 01, 2003 10:57 am    Post subject: [Comparative performance] Various forms of argument passing Reply with quote




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
====================
----------------------------------------------------------------------------
Quote:
| | 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:alexvn (AT) connect (DOT) to
http://mathforum.org/library/view/10978.html
==============================================






Back to top
Florian Weimer
Guest





PostPosted: Mon Sep 01, 2003 11:05 am    Post subject: Re: [Comparative performance] Various forms of argument pass Reply with quote



"Alex Vinokur" <alexvn (AT) bigfoot (DOT) com> writes:

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

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

Back to top
Jack Klein
Guest





PostPosted: Mon Sep 01, 2003 6:31 pm    Post subject: Re: [Comparative performance] Various forms of argument pass Reply with quote



On Mon, 1 Sep 2003 13:57:29 +0300, "Alex Vinokur" <alexvn (AT) bigfoot (DOT) com>
wrote in comp.lang.c++:

Quote:

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

Back to top
Alex Vinokur
Guest





PostPosted: Tue Sep 02, 2003 3:52 am    Post subject: Re: [Comparative performance] Various forms of argument pass Reply with quote


"Florian Weimer" <fw (AT) deneb (DOT) enyo.de> wrote

Quote:
"Alex Vinokur" <alexvn (AT) bigfoot (DOT) 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:alexvn (AT) connect (DOT) to
http://mathforum.org/library/view/10978.html
=====================================



Back to top
Alex Vinokur
Guest





PostPosted: Tue Sep 02, 2003 4:05 am    Post subject: Re: [Comparative performance] Various forms of argument pass Reply with quote


"Jack Klein" <jackklein (AT) spamcop (DOT) net> wrote

Quote:
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:alexvn (AT) connect (DOT) to
http://mathforum.org/library/view/10978.html
=====================================



Back to top
Mon
Guest





PostPosted: Tue Sep 02, 2003 11:34 am    Post subject: Re: [Comparative performance] Various forms of argument pass Reply with quote


Alex Vinokur <alexvn (AT) bigfoot (DOT) com> wrote

Quote:

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:alexvn (AT) connect (DOT) to
http://mathforum.org/library/view/10978.html
==============================================








Back to top
Mon
Guest





PostPosted: Tue Sep 02, 2003 11:35 am    Post subject: Re: [Comparative performance] Various forms of argument pass Reply with quote

Can the posters to this thread please confine themselves to their own
newsgroup & stop cross-posting
Alex Vinokur <alexvn (AT) bigfoot (DOT) com> wrote

Quote:

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:alexvn (AT) connect (DOT) to
http://mathforum.org/library/view/10978.html
==============================================








Back to top
llewelly
Guest





PostPosted: Tue Sep 02, 2003 6:07 pm    Post subject: Re: [Comparative performance] Various forms of argument pass Reply with quote

"Alex Vinokur" <alexvn (AT) bigfoot (DOT) com> writes:

Quote:
"Florian Weimer" <fw (AT) deneb (DOT) enyo.de> wrote

"Alex Vinokur" <alexvn (AT) bigfoot (DOT) 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.

Back to top
Florian Weimer
Guest





PostPosted: Sun Nov 23, 2003 12:54 pm    Post subject: Re: [Comparative performance] Various forms of argument pass Reply with quote

"Alex Vinokur" <alexvn (AT) bigfoot (DOT) com> writes:

Quote:
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.

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.