Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > [Comparative performance] Various forms of argument passing

Reply
Thread Tools

[Comparative performance] Various forms of argument passing

 
 
Alex Vinokur
Guest
Posts: n/a
 
      09-01-2003

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
(E-Mail Removed)
http://mathforum.org/library/view/10978.html
==============================================





 
Reply With Quote
 
 
 
 
Florian Weimer
Guest
Posts: n/a
 
      09-01-2003
"Alex Vinokur" <(E-Mail Removed)> writes:

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


Some implementations of std::string use copy-on-write semantics
internally.
 
Reply With Quote
 
 
 
 
Jack Klein
Guest
Posts: n/a
 
      09-01-2003
On Mon, 1 Sep 2003 13:57:29 +0300, "Alex Vinokur" <(E-Mail Removed)>
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
 
Reply With Quote
 
Alex Vinokur
Guest
Posts: n/a
 
      09-02-2003

"Florian Weimer" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
> "Alex Vinokur" <(E-Mail Removed)> 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
(E-Mail Removed)
http://mathforum.org/library/view/10978.html
=====================================


 
Reply With Quote
 
Alex Vinokur
Guest
Posts: n/a
 
      09-02-2003

"Jack Klein" <(E-Mail Removed)> wrote in message news(E-Mail Removed)...
> On Mon, 1 Sep 2003 13:57:29 +0300, "Alex Vinokur" <(E-Mail Removed)>
> 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
(E-Mail Removed)
http://mathforum.org/library/view/10978.html
=====================================


 
Reply With Quote
 
Mon
Guest
Posts: n/a
 
      09-02-2003

Alex Vinokur <(E-Mail Removed)> wrote in message
news:biv8u5$dj6cf$(E-Mail Removed)-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
> (E-Mail Removed)
> http://mathforum.org/library/view/10978.html
> ==============================================
>
>
>
>
>



 
Reply With Quote
 
Mon
Guest
Posts: n/a
 
      09-02-2003
Can the posters to this thread please confine themselves to their own
newsgroup & stop cross-posting
Alex Vinokur <(E-Mail Removed)> wrote in message
news:biv8u5$dj6cf$(E-Mail Removed)-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
> (E-Mail Removed)
> http://mathforum.org/library/view/10978.html
> ==============================================
>
>
>
>
>



 
Reply With Quote
 
llewelly
Guest
Posts: n/a
 
      09-02-2003
"Alex Vinokur" <(E-Mail Removed)> writes:

> "Florian Weimer" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
>> "Alex Vinokur" <(E-Mail Removed)> 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.
 
Reply With Quote
 
Florian Weimer
Guest
Posts: n/a
 
      11-23-2003
"Alex Vinokur" <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use a passing argument(returned argument)? ؿ Ruby 7 11-27-2008 03:53 AM
Passing a function as an argument and using the evaluated functionas an argument User1014 Javascript 1 11-30-2006 12:13 PM
forms authentication -- expired forms cookie vs. not provided forms cookie Eric ASP .Net Security 2 01-27-2006 10:09 PM
Forms authentication to secure various static content? Michael Brandt Lassen ASP .Net Security 3 11-24-2005 09:07 PM
Argument-per-argument Passing Trans Ruby 3 01-26-2005 05:58 PM



Advertisments