From owner-freebsd-questions@FreeBSD.ORG Tue Sep 13 21:38:24 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 EB038106566C for ; Tue, 13 Sep 2011 21:38:24 +0000 (UTC) (envelope-from talon@lpthe.jussieu.fr) Received: from shiva.jussieu.fr (shiva.jussieu.fr [134.157.0.129]) by mx1.freebsd.org (Postfix) with ESMTP id 68C618FC18 for ; Tue, 13 Sep 2011 21:38:24 +0000 (UTC) Received: from parthe.lpthe.jussieu.fr (parthe.lpthe.jussieu.fr [134.157.10.1]) by shiva.jussieu.fr (8.14.4/jtpda-5.4) with ESMTP id p8DLboTM026577 ; Tue, 13 Sep 2011 23:38:03 +0200 (CEST) X-Ids: 165 Received: from niobe.lpthe.jussieu.fr (niobe.lpthe.jussieu.fr [134.157.10.41]) by parthe.lpthe.jussieu.fr (Postfix) with ESMTP id F382321C7D; Tue, 13 Sep 2011 23:37:48 +0200 (CEST) Received: by niobe.lpthe.jussieu.fr (Postfix, from userid 2005) id E0E5D42AE; Tue, 13 Sep 2011 23:37:48 +0200 (CEST) Date: Tue, 13 Sep 2011 23:37:48 +0200 From: Michel Talon To: Gary Kline , freebsd-questions@freebsd.org Message-ID: <20110913213748.GA47026@lpthe.jussieu.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.2.3i X-Miltered: at jchkmail.jussieu.fr with ID 4E6FCD2E.000 by Joe's j-chkmail (http : // j-chkmail dot ensmp dot fr)! X-j-chkmail-Enveloppe: 4E6FCD2E.000/134.157.10.1/parthe.lpthe.jussieu.fr/parthe.lpthe.jussieu.fr/ Cc: Subject: Re: *caution* severely OT!! X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: 20110913193442.GA11369@thought.org List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 Sep 2011 21:38:25 -0000 "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