2

Say theoretically you just generate random numbers [using standard libraries] in as many threads as you can [bound by hardware]. How fast would C++ over Java?

no disk i/o, memory or gc. Just pure Math.random() calls across threads.

7
  • 8
    This is impossible to answer in general. Using what hardware platform, compiler, JVM version, compilation and runtime parameters, ...? And if you have all that defined, IMHO still it is the best to measure it for yourself... Commented Apr 13, 2011 at 8:10
  • 3
    A VERY GENERAL speed comparison is that C++ is 10x faster than Java, but can vary greatly. Commented Apr 13, 2011 at 8:12
  • 7
    @Cray, that was true sometime in the (distant) past, but AFAIK not anymore (since years). Regarding pure math functionality, C++ is still said to be noticeably faster, but far from 10x. And in some other areas and scenarios, Java can even outperform C++ by now. See also stackoverflow.com/questions/2163411/… . Commented Apr 13, 2011 at 8:13
  • 3
    In my experience: C++ is 2-3x faster. Can be much more if you are able to use SSE/AVX or other hardware specific specialties. Commented Apr 13, 2011 at 8:14
  • 2
    There is no theoretical answer - only ones determined by measurement. I tend to trust the following: shootout.alioth.debian.org/u32/… Commented Apr 13, 2011 at 8:16

3 Answers 3

2

Depends on hardware, OS and many other factors... I think this a very hard question to answer, cause there is too many variables involved. Why don't you test it?

Sign up to request clarification or add additional context in comments.

Comments

2

Test it. And Pay attention to the fact, that Java performance is not static above runtime. Because it can use a hot spot compiler, that compiles the hot spots after it detects them.

Comments

1

test both in the environment you will be deploying at.

2 Comments

And with realistic programs. It's fairly easy to write benchmarks which "prove" one is better than the other. For both sides.
Or to repeat a statement I heard a long time ago: Never trust a benchmark you didn't falsify yourself.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.