On 10 Apr., 16:41, "Ondrej Certik" <[EMAIL PROTECTED]> wrote:
> [...]
> That looks extremely interesting! It's just a simple .so file, that we
> call from python, it quickly compiles everything in memory and
> provides a compiled function (in memory), that you call using ctypes,
> am I right?
>
> I like this technology.
>
> Ondrej

Yeah, I'm now using libtcc via ctypes interface to compile to machine
code directly in memory. It works on Windows too, I only failed so far
to get math.h working. Compile time is not an issue anymore (according
to http://fabrice.bellard.free.fr/tcc/ it is able to compile the Linux
kernel in just 10 s on a 2.4 GHz CPU). A remaining issue is the
Python<->Overhead. Evaluating simple functions in a Python loop is
currently faster using pure Python. This motivated me to implement
evaluating functions on a range of numbers using dynamically generated
machine code. I'm using pointers, this means that Python and C are
using the same memory, so theres no interface overhead (except of
passing the pointer one time).

The result:

Running tests...
cexpr:
1/(g(x)*3.5)**(x - a**x)/(x**2 + a)
1/ pow((g(x)*3.5), (x - pow(a, x) )) /( pow(x, 2) + a)

compiling x**(1/2)*y**(1/2)...
f(0.5, 4) = 1.414214

Running benchmark...
big function:
compile time (including sympy overhead): 0.428471 s
for x = (0, 1, 2, ..., 999)/1000
20 times in 3 runs
compiled:      0.1288 0.1321 0.1334
Python lambda: 0.3407 0.3383 0.3380
Psyco lambda:  0.1547 0.1567 0.1561

simple function:
compile time (including sympy overhead): 0.012746 s
for x = (0, 1, 2, ..., 999)/1000
20 times in 3 runs
compiled:      0.0760 0.0775 0.0786
Python lambda: 0.0526 0.0527 0.0576
Psyco lambda:  0.0662 0.0661 0.0657

frange with f(x) = x**2 * sqrt(x) for x=1, ..., 1000000
in 3 runs including full compile time
frange:        0.2470 0.2186 0.2135
numpy:         0.2256 0.2162 0.2415

For big functions frange is probably faster than numpy.
I'm planning to implement evaluating on arrays too.
Any thoughts?

Vinzent
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to sympy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sympy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to