speeding things up with C++

Kay Schluehr kay.schluehr at gmx.net
Mon May 28 11:48:30 EDT 2007


On May 26, 11:19 am, bullockbefriending bard <kinch1... at gmail.com>
wrote:
> I've done all the requisite profiling and thought fairly deeply about
> the efficiency of my python code, but am still going to have to speed
> up the innermost guts of what I am doing.
>
> Essentially, I need to pass a list of 6-tuples containing only
> integers to my new sadly necessary super-fast compiled language
> function which i am not looking forward to writing:
>
> input: [(1,2,3,4,5,6), (7,8,9,10,11,12),...]
>
> and after much thrashing of processor resources, return data which
> looks like this to the Python calling environment:
>
> output: [( (1, 2), (1,), (12,), (13), (1, 7, 11), (9,) ), (  another
> nested tuple like preceding one  ), .... ]
>
> Each member of the returned list is a tuple containing 6 tuples, and
> each of those 6 tuples has at least one integer member. It would also
> be acceptable for the return values to be entirely nested lists
> instead of having the two innermost sequence types as tuples.
>
> I probably want to be using something like C++ because i'm going to
> need to use STL vectors and sets for what i'm doing in the algorithm
> i'm trying to speed up. IIRC Boost tuple is a bit painful for more
> than 10 elements + isn't really essential that I use a a non-mutable
> data type in what will be a small encapsulated bit of a much larger
> system.
>
> Anyway, I can probably very quickly figure out some hacked way to get
> the data into my function given that in the worst case I could take
> advantage of the knowledge that each input tuple always has 6
> elements, and simply pass in a big array of ints. Yes, I know this is
> a bit retarded, but I'm talking worst case assuming on very tight
> schedule and no time to delve deeply into SWIG or whatever. Similarly
> it wouldn't be too difficult to return the result as the mother all of
> all strings which i could then parse fairly easily.
>
> However, I hope someone reading this will be able to tell me that I'm
> being a total pessimist and that in fact it isn't very difficult to do
> what I want to do using SWIG. I'm not asking for a complete solution,
> more like some general pointers from someone who has actually done
> something similar before.
>
> As an added bonus, I wouldn't if this is 'easily' doable using Ocaml
> as the guts instead of C++, I'd be happy to know about it.

A just too obvious recommendation is to drop C++ and use D together
with the Pyd/celerid bridge. Yeah, it sounds a little esoteric but D
is really the Python among the statically typed imperative languages.

http://www.digitalmars.com/d/
http://pyd.dsource.org/index.html





More information about the Python-list mailing list