Skip to main content
Welcome guest. | Register | Login | Post

Performance of interpreted languages

9 replies [Last post]
libervisco's picture
Offline
Joined: 2006-05-04

Reading a tutorial on ruby, which starts with the introduction to basics of programming (although I know some already) there was an obligatory mention of two different types of programming languages, compiled and interpreted. Compiled programs don't have to be interpreted on the fly which seems to make their performance inherently better.

However advancements in interpreted languages and use of caching is apparently supposed to make the performance of interpreted languages better.

I'm curious though, it can't be that caching and those sort of "tricks" are the only ways in which interpreted languages gain on performance. There must be something more and closer to the nature of these programs. When talking about caching I usually think about something that's not ideal, but must be used or else.. it's going to be slow. Caching always implies delays that we don't want to have, right? It can't be an ideal solution.

So what else is there?

Thanks

free-zombie's picture
Offline
Joined: 2006-03-08
Most modern interpreted

Most modern interpreted languages probably use Just-in-time compilation of some form: when a function, module or something is used for the first time, it is compiled to a format that can be executed quickly, when it is used again, the code is available. In the case of python, a modules are saved as a machine-independent bytecode on disk and can be re-used as such on the next run.

Interpreted languages are slower, but not significantly more than bytecode-based languages like Java or .net. On modern machines, this makes little difference in practice - I/O is slower anyway. Realistically, only complex computations are significantly slower.

libervisco's picture
Offline
Joined: 2006-05-04
free-zombie wrote:Most
free-zombie wrote:

Most modern interpreted languages probably use Just-in-time compilation of some form: when a function, module or something is used for the first time, it is compiled to a format that can be executed quickly, when it is used again, the code is available. In the case of python, a modules are saved as a machine-independent bytecode on disk and can be re-used as such on the next run.

That sounds a lot like caching actually. Run and "compile" first time, cache and run from cache next time, if I understand correctly. So if you change something in the cached modules or functions in the meantime it will update this "cache" automatically, right?

OK I guess it's not a big deal on today's machines. Most of the problem with server loads and such come due to mysql more than actual code interpreting (although if code is good I suppose it would issue less mysql queries to do what it needs to do).

Thanks for an informative reply. Smiling

tbuitenh's picture
Offline
Joined: 2005-12-21
Yes, bytecode interpreters

Yes, bytecode interpreters usually are faster than direct interpreters, but not quite as fast as true compiled languages (with platform-dependent binaries). The advantage of using an interpreted language on a webserver is that it tends to be less vulnerable to buffer overflows (although it's perfectly possible to create a compiled language in which buffer overflows are impossible).

If you think about it, the binary created by a compiler is (more or less) a cached version of what a JIT-compiling interpreter creates.

A cache simply means you're trading space for time: keep your finished work so you won't have to do it again later. If you have enough space, and are managing it properly, caches are always good.

Can an interpreted language be made very fast? Sure can, just make it very simple Smiling .

Offline
Joined: 2006-06-11
By the way, for python

By the way, for python scripts, the moto is : "Speed is not a problem till it is a problem." :-)

I got better performance from Perl than Python, but since both are interpreted language, I prefer the one my brain likes reading and writing, and that is Python.

I can't stand reading Ruby.. it is so... wierd. I just don't like the way Ruby is written. Perl scripts are hard to maintain because a task can be written in incredible amount of ways, and it is hard to get back in when you haven't touched it for years.

For performance, if you run a .py, it turns into a .pyc (for compiled)

If you need C kind of performance, something like Pyrex can be used. It is a language very very similar and 100% compatible with Python (including bindings and objects) and can be automagically translated to C and compiled natively.

free-zombie's picture
Offline
Joined: 2006-03-08
I don't know much about

I don't know much about Pyrex, but PyPy is interesting - it is a pure-python implementation of python and includes a machine code compiler, which can compile PyPy itself/

libervisco's picture
Offline
Joined: 2006-05-04
WaterSoul wrote: By the
WaterSoul wrote:

By the way, for python scripts, the moto is : "Speed is not a problem till it is a problem." :-)

That's interesting. It does make sense. Smiling

Anyway, I'm thinking of trying CakePHP before I go into Ruby now.. I was reading some discussions on PHP vs. Ruby and since Drupal runs PHP and I already have some familiarity with it, that may be a better way to go.. Ruby or Python can come next. Smiling

Thanks

Offline
Joined: 2006-06-11
otherwise I can tell I'm

otherwise I can tell I'm using django (python based framework) and it does an awesome job!

http://blog.watersoul.ca runs with django, I wrote all the 'blog' code in python, and there isn't much!

libervisco's picture
Offline
Joined: 2006-05-04
So that's what django is

So that's what django is all about, a python framework. Sounds great. Smiling

Btw, that blog looks awesome. Smiling

Offline
Joined: 2006-06-11
Thanks Here is

Thanks :-)

Here is informations about django caching capabilities : http://www.djangoproject.com/documentation/cache/

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.