Java vs. C execution time

Page 3 - Seeking answers? Join the AnandTech community: where nearly half-a-million members share solutions and discuss the latest tech.

Leros

Lifer
Jul 11, 2004
21,867
7
81
I would think the JVM would be faster for certain applications. One advantage of JIT compilation is that the JVM can recompile the code wtih optimizations based on collected runtime data. This could allow the JVM to perform better optimization than the C compiler, leading the Java program having better performance.
 

exdeath

Lifer
Jan 29, 2004
13,679
10
81
Quick and dirty but:
---------------------
Code:
mov eax, op2
add op1, eax


Is always going to be faster than:
-------------------------------------
Code:
mov ebx, opcode_jmp_table_base

vm_loop:
call do_other_vm_stuff
; fetch an opcode and emulate it
mov eax, [opcode_pointer]
lea edx, [ebx + 4*eax] ; load opcode dword jump address for opcode index in eax from jmp table
jmp [edx]

...
...
...
; opcode add a, 
OP_ADD:
mov eax, [a] ; fetch a
add eax, [b] ; add b to a
mov [a], eax
inc opcode_pointer
jmp vm_loop
; opcode sub a, b
...
...
...
; more opcodes and cache killing stuff blah blah blah

opcode_jmp_table_base
...
...
...
.dd OP_THIS
.dd OP_THAT
.dd OP_ADD
.dd OP_SUB
.dd OP_MORE
...
...

Not to mention the memory bloat and subsequent I/O penalties for having to load a 8 trillion gigabyte vm executable file for calc.exe.

Hello World in C on a Windows PC is a 12k PE with the bare minimum 3 sections with 4k alignment and 99% of it zero padded. Maybe 2 pages, don't recall what the minimum page count is for a still compliant and valid PE that will load.

Hello World on an Android is what a 30 MB .apk? Seriously? I can get on my NES, initialize all the hardware, procedurally create alpha numeric font tiles for a graphics chip that doesn't have a native text mode, and display Hello World in probably < 1 KB. Why does Android/Java use 30 MB?

Evils like Java are the reason we have web browsers that require 64 GB of RAM to go to www.google.com and why a simple device like an alarm clock needs 2 GB RAM and a 4 core ARM to tell time we did just fine in 1980 on a 6502 or Z80 with 128 bytes.

I'm not saying enterprise applications should be written in assembly but JFC what's up with the memory footprint of mobile apps and browsers and well just everything lately? And related I hate the file formats where these applications have a million files and sub directories with all these 1k files, because random access storage I/O hasn't already been the Achilles heal of computing for oh the last 3 decades.

Applications like Chrome and Lotus Notes and VM based operating systems like Android are prime examples of RAM and file bloat.
 
Last edited:

postmortemIA

Diamond Member
Jul 11, 2006
7,721
40
91
I would think the JVM would be faster for certain applications. One advantage of JIT compilation is that the JVM can recompile the code wtih optimizations based on collected runtime data. This could allow the JVM to perform better optimization than the C compiler, leading the Java program having better performance.
You can profile and optimize C/C++ applications too. Build with profiler and then re-optimize based on results. With C you have many ways to optimize program, and you're in total control... you have also more ways to screw it up ( buffer overflows, etc.)
 

beginner99

Diamond Member
Jun 2, 2009
5,228
1,603
136
You can profile and optimize C/C++ applications too. Build with profiler and then re-optimize based on results. With C you have many ways to optimize program, and you're in total control... you have also more ways to screw it up ( buffer overflows, etc.)

You can but research has shown that Java usually is faster for the same amount of work put into the code. Optimizing C will take hours to weeks. Yeah, that makes sense for crucial parts of crucial software like operating system, database management systems and the likes. But for standard business apps? Waste of time. Especially because they are usually latency-limited (IO) anyway due to database lookups over network.
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |