3

Java programs can outperform compiled programming languages like C in specific tasks. It is because the JVM has runtime information, and does JIT compiling when necessary (i guess).

(example: http://benchmarksgame.alioth.debian.org/u32/performance.php?test=chameneosredux)

Is there anything like this for a compiled language? (i am interested in C first of all)

After compiling the source, the developer runs it and tries to mimic typical workload. A tool gathers information about the run, and then according to this data, it recompiles again.

Seki
  • 11,135
  • 7
  • 46
  • 70
jsaak
  • 587
  • 4
  • 17
  • For compiled languages, it's called *profiling*. Some profilers will give you information that you can use to manually optimize the code, others can give information that you feed back to the compiler so it can make better optimization choices. – Some programmer dude Dec 16 '14 at 12:58
  • do you have an example where a well written java program outperforms an equally well written C program? – Andreas Grapentin Dec 16 '14 at 13:14
  • 1
    Look more closely at the example: On multi-core the C gcc #5 program shows both faster CPU time and Elapsed time. That C program degrades on one-core because the program is trying to use core-affinity and that is interacting with the measurement script which is forcing the programs onto a single core. The example DOES NOT show what you thought. http://benchmarksgame.alioth.debian.org/u32q/performance.php?test=chameneosredux – igouy Dec 22 '14 at 16:33

3 Answers3

1

gcc has -fprofile-arcs

from the manpage:

-fprofile-arcs
    Add code so that program flow arcs are instrumented. During execution the 
    program records how many times each branch and call is executed and how many 
    times it is taken or returns. When the compiled program exits it saves this 
    data to a file called auxname.gcda for each source file. The data may be 
    used for profile-directed optimizations (-fbranch-probabilities), or for 
    test coverage analysis (-ftest-coverage).
Andreas Grapentin
  • 5,499
  • 4
  • 39
  • 57
  • more detailed answer here: http://stackoverflow.com/questions/13881292/gcc-profile-guided-optimization-pgo – jsaak Dec 17 '14 at 08:50
0

I don't think the jvm has ever really beaten well optimized C code.

But to do something like that for c, you are looking for profile guided optimization, where the compiler use runtime information from a previous run, to re-compile the program.

MTilsted
  • 5,425
  • 9
  • 44
  • 76
0

Yes there are some tools like this, I think it's known as "profiler-guided optimization".

There are a number of optimizations. Importantly is to reduce backing-store paging, as well as the use of your code caches. Many modern processors have one code cache, maybe a second level of code cache, or a second unified data and code cache, maybe a third level of cache.

The simplest thing to do is to move all of your most-frequently used functions to one place in the executable file, say at the beginning. More sophisticated is for less-frequently-taken branches to be moved into some completely different part of the file.

Some instruction set architectures such as PowerPC have branch prediction bits in their machine code. Profiler-guided optimization tries to set these more advantageously.

Apple used to provide this for the Macintosh Programmer's Workshop - for Classic Mac OS - with a tool called "MrPlus". I think GCC can do it. I expect LLVM can but I don't know how.

Mike Crawford
  • 2,232
  • 2
  • 18
  • 28