Re: Directly converting Python to C using the C API
On Dec 3, 2009, at 9:09 PM, Emmanuel Bengio wrote: I'm fairly new to the python world, and I often heard critics about it's speed, and also about it's "non-compilability". Then I thought, there is a complete C API that manages Python itself. Would it be feasible to transform pure Python code into pure Python "C API" code? It would spare the parsing time, which seems to be the an important factor in Python's speed. Given the following example: x=0 for i in xrange(10): x+=x*i On my machine, this takes 79ms to run. while this: PyObject* x = PyInt_FromLong(0); int i; for (i=0;i<10;i++) { x=PyNumber_Add(x,PyNumber_Multiply(x,PyInt_FromLong(i))); } takes about 16 ms to run. Any thoughts? This is such a good idea that it has become a popular project: http://www.cython.org/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Directly converting Python to C using the C API
On Thu, Dec 3, 2009 at 6:09 PM, Emmanuel Bengio wrote: > I'm fairly new to the python world, and I often heard critics about it's > speed, and also about it's "non-compilability". > Then I thought, there is a complete C API that manages Python itself. > Would it be feasible to transform pure Python code into pure Python "C API" > code? It would spare the parsing time, which seems to be the an important > factor in Python's speed. > > Given the following example: > x=0 > for i in xrange(10): > x+=x*i > On my machine, this takes 79ms to run. > while this: > PyObject* x = PyInt_FromLong(0); > int i; > for (i=0;i<10;i++) > { > x=PyNumber_Add(x,PyNumber_Multiply(x,PyInt_FromLong(i))); > } > takes about 16 ms to run. > Any thoughts? You're going to have to check that xrange() hasn't been rebound for starters. Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Directly converting Python to C using the C API
I'm fairly new to the python world, and I often heard critics about it's speed, and also about it's "non-compilability". Then I thought, there is a complete C API that manages Python itself. Would it be feasible to transform pure Python code into pure Python "C API" code? It would spare the parsing time, which seems to be the an important factor in Python's speed. Given the following example: x=0 for i in xrange(10): x+=x*i On my machine, this takes 79ms to run. while this: PyObject* x = PyInt_FromLong(0); int i; for (i=0;i<10;i++) { x=PyNumber_Add(x,PyNumber_Multiply(x,PyInt_FromLong(i))); } takes about 16 ms to run. Any thoughts? -- Emmanuel Bengio -- http://mail.python.org/mailman/listinfo/python-list