Quantcast
Channel: C++ and Java performance - Stack Overflow
Viewing all articles
Browse latest Browse all 10

C++ and Java performance

$
0
0

this question is just speculative.

I have the following implementation in C++:

using namespace std;void testvector(int x){  vector<string> v;  char aux[20];  int a = x * 2000;  int z = a + 2000;  string s("X-");  for (int i = a; i < z; i++)  {    sprintf(aux, "%d", i);    v.push_back(s + aux);  }}int main(){  for (int i = 0; i < 10000; i++)  {    if (i % 1000 == 0) cout << i << endl;    testvector(i);  }}

In my box, this program gets executed in approx. 12 seconds; amazingly, I have a similar implementation in Java [using String and ArrayList] and it runs lot faster than my C++ application (approx. 2 seconds).

I know the Java HotSpot performs a lot of optimizations when translating to native, but I think if such performance can be done in Java, it could be implemented in C++ too...

So, what do you think that should be modified in the program above or, I dunno, in the libraries used or in the memory allocator to reach similar performances in this stuff? (writing actual code of these things can be very long, so, discussing about it would be great)...

Thank you.


Viewing all articles
Browse latest Browse all 10

Latest Images

Trending Articles





Latest Images