Download presentation
Presentation is loading. Please wait.
1
Which slows more? Java or C++?
2
My background unusual, diverse, broad
N years in academia (not CS); ~13.5 IBM Watson; ~3 Google Chicago ~1 year writing Fortran; ~1 year writing APL; ~1 year writing assembler (IBM 360); ~2 years [net] writing “HPL”; ~2 years writing C++ (98); ~15 years writing Java Currently on Java 7 … large codebases tend to migrate slowly …
3
Why do we care about code speed, anyway?
Mostly we don’t: other things matter more (correctness, robustness, security, …) Often we won’t, b/c we are dominated by other latencies (network, database, …) Sometimes we do: computation-intensive, bit-blitting, games, attempting to crash the NYSE, …
4
OK, let’s just admit that C++ is almost always faster
… by at least a small amount … Et f***ing cetera … The C++/Java-speed-debate is often called a religious war: (a) all positions are absolute and extreme, and (b) it’s over nothing
5
… so what if it is? All arguments for using C++ (instead of Java) just because C++ is faster are also arguments for using C (instead of C++) just because C is even faster, … … which in turn are arguments for using assembler (instead of C) just because assembler is even faster … … which in turn are arguments for building a specialized chip (instead of writing assembler) just because chip instructions are even faster … … and yes, that has been done: IBM’s “Deep Blue”
6
When coding in the Real World®™…
Many considerations besides speed are relevant, and the language you use will depend on your … existing code-base company policy available libraries …
7
Having Choices is good …
Most people drive automatics (“Java”), but people who love control, and small gains in mileage, want to drive sticks (“C++”) C++ and Java are both widely used C++ and Java are both actively supported and growing C++ and Java are both imperative languages … … but sometimes you need a functional language
8
And the top reason … … some big finance firms do not even use C++!
Goldman-Sachs uses their own secret language, “SLANG” Jane Street and Bloomberg use OCAML (
9
The cases against using C++ on grounds other than performance:
code-understanding and maintenance time to market is also a time that matters ensuring correctness “our bugs run faster”: even financial code needs to be correct! robustness (C++ is brittle) even financial code is bad if it crashes often! security (C++ is famously the source of security holes) even financial code needs to be secure!
10
OK, now what? So, in a situation where your code-base is Java, and yet your code still needs to be performant, what’s a coder to do? First Law of Latency: “your analysis is wrong!” … instead, run a carefully-designed benchmark!
11
The threefold way of writing fast Java:
Choose the right algorithm (true in any language) will depend on the *actual* limits to your “n” in the Real World®™, n-squared can be better than n-log-n for constrained values of n with the right constant factors Write clean code (true in any language) will be easier for the JIT to optimize Benchmarking is hard (true in any language) even Wikipedia knows that: …
12
Always remember … “premature optimization is the root of all evil”
Donald E. Knuth Joshua Bloch, Effective Java, # 55
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.