[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 05:41:08 CEST 2015


The python functions usage is like UDF.
The function parameters might be different from time to time.
We are not able to get all parmaters we need to call at the begining. And
we' ve no ideas how many times we need to call. It all depends on how user
input the command at the front end.

And one more question, how to get the return value from pypy function?

On Wed, May 13, 2015 at 11:01 AM, Ryan Gonzalez <rymg19 at gmail.com> wrote:

> Couldn't you just write the loop in Python?
>
> On May 12, 2015 9:42:47 PM CDT, Yicong Huang <hengha.mao at gmail.com> wrote:
>
>> 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
>>
>> ------------------------------
>>
>> pypy-dev mailing list
>> pypy-dev at python.org
>> https://mail.python.org/mailman/listinfo/pypy-dev
>>
>>
> --
> Sent from my Android device with K-9 Mail. Please excuse my brevity.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pypy-dev/attachments/20150513/f7252218/attachment.html>


More information about the pypy-dev mailing list