[pypy-dev] How to call the "same pypy function" from C for thousands of times?

Yicong Huang hengha.mao at gmail.com
Wed May 13 04:42:47 CEST 2015


Hi,

I read the document "Embedding Pypy". It introduces the method to call pypy
function from C.
In our scenaro, we would like to call the same pypy function from C for
thousands of times or even millions of times.
Following the document, the code is like this:

 for(i = 0; i < count; i++){
        res = pypy_execute_source(pyBuffer);
        if(res)
           break;
 }
 if (res || i < count) {
       printf("Error calling pypy_execute_source!\n");
  }

However, the code is quite slow for reasons:
1. Pypy treats the same function call for a new function every time. It
took time to do parsing, analysing and such a lot of work.
2. JIT could not give any benifits for the single function call.

For looping 100,000 times in C code, it took about 1120.2 secondes.
However, the same function executing in pypy for 100,000 times only cost
about 3.7 secodes.

Do we have any ideas to improve this case?
For example, could we expose the function pointer in pypy to C, so that C
code is able to call the same pypy function in the loop?

Thanks!

-Ethan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pypy-dev/attachments/20150513/f2129b3c/attachment.html>


More information about the pypy-dev mailing list