views:

310

answers:

6

I'm making an application that analyses one or more series of data using several different algorithms (agents). I came to the idea that each of these agents could be implemented as separate Python scripts which I run using either the Python C API or Boost.Python in my app.

I'm a little worried about runtime overhead TBH, as I'm doing some pretty heavy duty data processing and I don't want to have to wait several minutes for each simulation. I will typically be making hundreds of thousands, if not millions, of iterations in which I invoke the external "agents"; am I better of just hardcoding everything in the app, or will the performance drop be tolerable?

Also, are there any other interpreted languages I can use other than Python?

A: 

you could probably create an embedded language using C++ templates and operator overloading, see for example ublas or ftensor matrix languages. i do not think python or other interpreted languages of is suitable for having numbercrunching/data processing.

aaa
+1  A: 

For millions of calls (from I'm assuming c++, because you mentioned boost) into python, yes: you will notice a performance hit. This may or may not be significant - perhaps the speed gain of trying out new 'agents' would be greater than the hit. Python does have fast numerical libraries (such as numpy) that might help, but you'll still incur overhead of marshalling data, calling into python, the gil, etc.

Yes, you can embed many other languages: check out lua. Also, check out swig.org, which can connect to many other languages besides python.

Colin
+7  A: 

Yes, tons. Lua and Python seems to be the most popular:

Embedding Lua

Embedding Python

Embedding Ruby

Embed Perl

Embed JavaScript

There are dozens of JavaScript engines around, this is just an example. Some of them are also frighteningly quick.

Skurmedel
In my opinion, Lua is likely the most well-documented language for embedded, it's sorta a de facto standard for game development.
Paul Nathan
Indeed, it's very simple. I haven't embedded it myself but used it in a custom Garry's Mod module, and used the C API to pass stuff. It was straightforward enough for my then 15 year old brain (which had the computing capacity of a sponge.)
Skurmedel
Tcl may challenge Lua as the most well-documented language, though that's subjective. It's also been around longer than Lua. It's not as "hot" as lua, but it is at least equally as good.
Bryan Oakley
Feel free to add it to the list.
Skurmedel
Lua's interpreter is smaller than Python's, but it was originally created for doing configurations, so Python is less error prone and has more robust syntax. It also benefits hugely from NumPy for number crunching, though adding external modules like that also makes embedding Python a larger task.
KingRadical
+2  A: 

I will typically be making hundreds of thousands, if not millions, of iterations in which I invoke the external "agents"

The performance drop will be noticeable, perhaps painful. If you can put the data into arrays and process it in batches using NumPy, it should be much faster.

NumPy makes it super easy to do any kind of arithmetic a million times in a row. For example, squaring every element of an array is like this:

>>> x = numpy.array([1, 2, 3, 4, 5, 6, 7])
>>> x**2
array([1, 4, 9, 16, 25, 36, 49])

Super easy, and the tight inner loop here is actually implemented in C.

Of course NumPy can also do more advanced number-crunching.

Jason Orendorff
+3  A: 

Tcl was designed from the ground up to be an embedded language.

Bryan Oakley
Same answer as part of mine while I was editing. +1 for obvious genius. :-)
T.E.D.
+2  A: 

I believe tcl and Rexx were both intended for this purpose.

T.E.D.