I have a library written in C, and I have 2 applications written in C ++ and C. This library is a communication library, so one of the API calls looks like this:
int source_send( source_t* source, const char* data );
In application C, the code does something like this:
source_t* source = source_create(); for( int i = 0; i < count; ++i ) source_send( source, "test" );
Where does the C ++ application do it:
struct Source { Source() { _source = source_create(); } bool send( const std::string& data ) { source_send( _source, data.c_str() ); } source_t* _source; }; int main() { Source* source = new Source(); for( int i = 0; i < count; ++i ) source->send( "test" ); }
On Intel Core i7, C ++ code produces almost exactly 50% more messages per second. While on Intel Core 2 Duo it produces almost exactly the same amount of messages per second. (The i7 core has 4 cores with two processing threads each)
I'm curious what kind of magic the equipment does to take it off. I have some theories, but I thought I was getting a real answer :)
Edit: More info from comments
The compiler is visual C ++, so this is a window (both of them)
The implementation of the communication library creates a new thread for sending messages. Source_create creates this stream.
c ++ c cpu cpu-architecture hardware
Charles
source share