[Fwd: Re: [Discuss] Interpreters vs Compilers]
pw
p.willis at telus.net
Thu Mar 13 14:52:49 PDT 2008
John Blomfield wrote:
>
> I don't have anything more authoritative to add than I did last night,
> except to say again, that Python and Java for example compile their
> source code into "bytecode" which is slightly optimized code but it is
> not machine code. A byte code file still has to be interpreted, which
> means translated into machine code instructions line by line by the so
> called "Virtual Machine". Each platform needs the Virtual Machine
> running to run a bytecode file. In the case of a loop, the loop is in
> bytecode and must be interpreted line by line every time through the
> loop, into possibly many many machine instructions. In the case of a
> compiled C program the binary is in machine instructions that the CPU
> understands without interpretation, hence the speed. The optimization
> in C is very very good, so good that it is almost impossible for the
> average programmer to do better using Assembler. I once did some
> programming of micro-controllers, which are quite slow compared to the
> typical PC, in both Microchip Assembler and Microchip C and the C
> compiler always won. This one of the reasons most hardware is
> programmed in C, including Linux and Python I think. Python certainly
> uses a lot of built in mathematical functions that are written in C to
> help speed its execution.
>
> Its all a question of horses for courses! Scripting languages like Perl
> and Python are often referred to as the "glue" that sticks the C and C++
> modules together. So if you want Zoom Zoom go C!
>
> John Blomfield
byte code is a type of pseudo machine code.
This code is run in a virtual machine much like
emulating the operation of a microprocessor.
The java virtual machine, for example, is merely a
microprocessor/toolkit architecture that has been defined
to use a machine language of java byte code. The virtual machine
is compiled for various computers to provide java system emulation.
The speed of this emulation is related to the optimizations built
into the virtual machine as compiled for your particular system.
(ie: system meaning I86 or PPC or sparc or etc..)
Hence, the byte code process is not exactly akin to
'interpretation'. The interpretation has already been
done in the compilation from source code to byte code.
In theory byte code processing can be as fast as
machine code since the virtual machine can directly
transfer the values of byte code to applicable machine
level instructions prior to running the application,
thus running the application in 'native' machine code.
Peter
More information about the Discuss
mailing list