Directly converting Python to C using the C API

2009-12-03 Thread Emmanuel Bengio
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;i10;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


[issue6924] struct.unpack weird behavior with bi (byte then integer)

2009-09-16 Thread Emmanuel Bengio

New submission from Emmanuel Bengio beng...@gmail.com:

Using the following command in Python 2.6.1:

 struct.unpack(BI,12345)
Traceback (most recent call last):
  File pyshell#1, line 1, in module
struct.unpack(BI,12345)
error: unpack requires a string argument of length 8

I get this error message. What confused me was that doing
 struct.unpack(IB,12345)
(875770417, 53)
Worked just fine.

I have found out that this only happens using the native byte
order(@), which is the default.
For Example:
 struct.unpack(!BI,12345)
(49, 842216501)
Works, and all other variants, =, ,  (native standard,little endian,
and small endian) also do.

I haven't found anything about that in the documentation.

Also, the requested 3 other bytes arent event used:
 struct.unpack(I,abcd)
(1684234849,) # see the big number starting with 16
 ord(x)
120
 struct.unpack(BI,xabcd) # we get the error
Traceback (most recent call last):
  File pyshell#7, line 1, in module
struct.unpack(BI,xabcd)
error: unpack requires a string argument of length 8
 struct.unpack(BI,xabcdefg)
(120, 1734763876) # not the same here
 struct.unpack(BI,xabcabcd)
(120, 1684234849) # same here
 struct.unpack(BI,x___abcd)
(120, 1684234849) # same again

--
components: Library (Lib)
messages: 92724
nosy: Manux
severity: normal
status: open
title: struct.unpack weird behavior with bi (byte then integer)
type: behavior
versions: Python 2.6

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6924
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com