From owner-freebsd-questions@FreeBSD.ORG Tue Sep 13 21:48:00 2011 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7827D1065673 for ; Tue, 13 Sep 2011 21:48:00 +0000 (UTC) (envelope-from kline@thought.org) Received: from thought.org (plato.thought.org [209.180.213.209]) by mx1.freebsd.org (Postfix) with ESMTP id 55F698FC19 for ; Tue, 13 Sep 2011 21:47:59 +0000 (UTC) Received: by thought.org (Postfix, from userid 1001) id 4C93BE8207D; Tue, 13 Sep 2011 14:47:59 -0700 (PDT) Date: Tue, 13 Sep 2011 14:47:59 -0700 From: Gary Kline To: 20110913193442.GA11369@thought.org Message-ID: <20110913214759.GD12076@thought.org> References: <20110913213748.GA47026@lpthe.jussieu.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20110913213748.GA47026@lpthe.jussieu.fr> Organization: Thought Unlimited. Public service Unix since 1986. Of_Interest: With 25 years of service to the Unix community. User-Agent: Mutt/1.5.21 (2010-09-15) Cc: freebsd-questions@freebsd.org Subject: Re: *caution* severely OT!! X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 Sep 2011 21:48:00 -0000 On Tue, Sep 13, 2011 at 11:37:48PM +0200, Michel Talon wrote: > Date: Tue, 13 Sep 2011 23:37:48 +0200 > From: Michel Talon > Subject: Re: *caution* severely OT!! > To: Gary Kline , freebsd-questions@freebsd.org > > "C. P. Ghost" wrote: > > On Tue, Sep 13, 2011 at 9:34 PM, Gary Kline wrote: > > > guys, > > > > > > can anyone start me on the way of porting a python program to C? > > > tia, > > > > Gary, > > > > if you experience a performance bottleneck somewhere, > > you may be better off performing some timings to > > determine the exact cause, and then to port the specific > > function(s) to a C module. Hints: ctypes, SWIG. Porting > > the whole program may not be necessary. Save yourself > > some quality time for other more pleasant tasks in life. ;-) > > > > But if you really must, I suggest to port the program to > > C++ instead of C, because there, you can make use of > > the excellent STL data types and containers, that match > > Python's somewhat. You may also consider using boost > > libraries, if the STL isn't enough. > > I concur with you. If you want just to resolve a bottleneck in python > there are very low cost solutions such as using things like pyrex. > You have a nice discussion here: > http://www.scipy.org/PerformancePython > Using pyrex is very similar to programming python but at a single stroke > you get huge performance boost. > > If you want to rewrite the thing entirely, the problem is that python > has many high level constructs, like dictionaries, etc. which are very > convenient, but that you would need to simulate in C with huge > programming cost. While C++ has such things in standard extensions, so, > if you are not afraid by the syntactic difficulties of C++ it is a > cheaper solution, otherwise it may be terrible. > > In the case of the example cited above, there was 0 performance benefit of > using C++ over pyrex. There is a language which is syntactically very > close to python and has the same facilities, but ends up in machine > code, this could interest you, it is Common Lisp. Here the translation > would be cheap and direct. It may be that the end result is very fast, > C-like, or it may be that the end result is almost as slow as python, > there is black magic here. > > > > -- > > Michel TALON Thanks to everyone who replied on and off list. i shoulf have said C or C++. gary > -- Gary Kline kline@thought.org http://www.thought.org Public Service Unix Journey Toward the Dawn, E-Book: http://www.thought.org The 8.51a release of Jottings: http://jottings.thought.org