Which slows more? Java or C++?

Slides:



Advertisements
Similar presentations
Growth-rate Functions
Advertisements

CS 300 – Lecture 20 Intro to Computer Architecture / Assembly Language Caches.
Cmpt-225 Algorithm Efficiency.
CS503: First Lecture, Fall 2008 Michael Barnathan.
27-Jun-15 Profiling code, Timing Methods. Optimization Optimization is the process of making a program as fast (or as small) as possible Here’s what the.
CS 300 – Lecture 2 Intro to Computer Architecture / Assembly Language History.
30-Jun-15 Profiling. Optimization Optimization is the process of making a program as fast (or as small) as possible Here’s what the experts say about.
CS2336: Computer Science II
SM3121 Software Technology Mark Green School of Creative Media.
Software Development Unit 6.
Programming Aesthetics learned from making independent games April 1, 2011.
1 TOPIC 1 INTRODUCTION TO COMPUTER SCIENCE AND PROGRAMMING Topic 1 Introduction to Computer Science and Programming Notes adapted from Introduction to.
Introduction to Algorithms Jiafen Liu Sept
/425 Declarative Methods - J. Eisner /425 Declarative Methods Prof. Jason Eisner MWF 3-4pm (sometimes 3-4:15)
E145/STS173 Case Study Tips E145/STS173 Case Study Tips Professors Tom Byers and Randy Komisar Stanford University With special thanks to: Jan Chong Copyright.
1 ENERGY 211 / CME 211 Lecture 26 November 19, 2008.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Advanced Compilers CMPSCI 710 Spring 2004 Lecture 1 Emery Berger University of Massachusetts,
Debugging and Profiling With some help from Software Carpentry resources.
Evolutionary Security CS 610: Advanced Security Gabriel Daleson.
CS 206 Introduction to Computer Science II 09 / 18 / 2009 Instructor: Michael Eckmann.
Compiling “premature optimization is the root of all evil.” -Donald Knuth.
Testing Mutable Objects CS 5010 Program Design Paradigms "Bootcamp" Lesson © Mitchell Wand, This work is licensed under a Creative Commons.
Reduced Instruction Set Computing Ammi Blankrot April 26, 2011 (RISC)
Hardware Trends CSE451 Andrew Whitaker. Motivation Hardware moves quickly OS code tends to stick around for a while “System building” extends way beyond.
Hardware Trends CSE451 Andrew Whitaker. Motivation Hardware moves quickly OS code tends to stick around for a while “System building” extends way beyond.
High-level language programming paradigms. Programming languages come in many forms or 'paradigms'. Each form of language offers advantages over other.
Introduction CSE 410, Spring 2005 Computer Systems
CSC 108H: Introduction to Computer Programming Summer 2012 Marek Janicki.
Assembly Language Basic job of a CPU: execute lots of instructions. Instructions are the primitive operations that the CPU may execute. Different CPUs.
CSC 108H: Introduction to Computer Programming Summer 2012 Marek Janicki.
Pragmatic Drupal Development John Fiala Developer.
Wireless Networking What You need to remember. What you need: A wireless router (Microsoft MN-700 Wireless router shown) A Wireless Adapter (Microsoft.
Are you ready to start? Open the car door and get in Check tyres
Speed up your computer or device
Vocabulary Algorithm - A precise sequence of instructions for processes that can be executed by a computer Low level programming language: A programming.
High or Low Level Programming Language? Justify your decision.
Shellsort.
Protecting Memory What is there to protect in memory?
Protecting Memory What is there to protect in memory?
Scalability for Search
CPSC 315 – Programming Studio Spring 2012
UNIT 4 – THE COST OF FREE LESSON 4.
Advanced Compilers CMPSCI 710 Spring 2003 Lecture 1
Questions on “The Problem of Social Cost”
Introduction to Problem Solving and Programming CS140: Introduction to Computing 1 8/19/13.
Compiler Construction
Portability CPSC 315 – Programming Studio
Introduction to Data Structures
Prof. Jason Eisner MWF 3-4pm (sometimes 3-4:15)
Bitwise Operations and Bitfields
Best Practices for Computer Security and Maintenance
Life Law #1 Your Either Get it, or You Don’t
DEBUGGING CS2110.
Programming.
Analysis of Algorithms II
E145/STS173 Case Study Tips Professors Tom Byers and Randy Komisar
Testing Mutable Objects
UNIT 4 – THE COST OF FREE LESSON 6.
CSE 373 Data Structures and Algorithms
Analysis of Algorithms
DW Daniel High, SC; Jan 25, 2010 Murali Sitaraman
Motion: Speed & Acceleration
Analysis of Algorithms
CSE 373: Data Structures and Algorithms
EE 155 / Comp 122 Parallel Computing
Reasons To Study Programming Languages
Performance and Code Tuning Overview
Optimizing Compilers CISC 673 Spring 2009 Course Overview
Analysis of Algorithms
U3L4 Using Simple Commands
Presentation transcript:

Which slows more? Java or C++? ptk@google.com

My background unusual, diverse, broad N years in academia (not CS); ~13.5 years @ IBM Watson; ~3 years @ 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 …

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, …

OK, let’s just admit that C++ is almost always faster … by at least a small amount … https://en.wikipedia.org/wiki/Java_performance#Memory_usage https://en.wikipedia.org/wiki/Comparison_of_Java_and_C%2B%2B#Performance http://raid6.com.au/~onlyjob/posts/arena/ http://forums.xkcd.com/viewtopic.php?f=11&t=108685 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

… 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”

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 …

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

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 (https://ocaml.org/learn/companies.html)

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!

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!

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: https://en.wikipedia.org/wiki/Benchmark_(computing) …

Always remember … “premature optimization is the root of all evil” Donald E. Knuth Joshua Bloch, Effective Java, # 55 http://homepages.dcc.ufmg.br/~rodolfo/dcc030-2-11/Effective%20Java%20Item%2055.htm