Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeder2.ecngs.de!ecngs!feeder.ecngs.de!xlned.com!feeder7.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'that?': 0.05; 'python': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'message- id:@dough.gmane.org': 0.16; 'received:80.91.229.3': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-dialin.net': 0.16; 'respondents': 0.16; 'shallow': 0.16; 'wrote:': 0.17; 'tests': 0.18; '(or': 0.18; 'code.': 0.20; 'seems': 0.23; 'header:User-Agent:1': 0.26; 'replace': 0.27; 'header:X-Complaints-To:1': 0.28; 'function': 0.30; 'code': 0.31; 'to:addr:python-list': 0.33; 'there': 0.35; 'add': 0.36; 'received:org': 0.36; 'but': 0.36; 'subject:: ': 0.38; 'unit': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'your': 0.60; 'different': 0.63; 'taking': 0.65; 'functions)': 0.84; 'rita': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: profiling and optimizing Date: Tue, 31 Jul 2012 15:23:56 +0200 Organization: None References: Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p5084988f.dip.t-dialin.net User-Agent: KNode/4.7.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 19 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1343741027 news.xs4all.nl 6945 [2001:888:2000:d::a6]:43042 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:26307 Rita wrote: > I recently inherented a large python process and everything is lovely. As > a learning experience I would like to optimize the code so I ran it thru > the profiler > > python -m cProfile myscript.py > > It seems majority of the time is taking in the deep copy but that seems to > come from a function (or functions) in the code. Is there a way to > optimize that? perhaps have a C implementation of the deep copy? Would > that be feasible? To give what the other respondents said a different angle: if you replace the deep with a shallow copy: do your unit tests start to fail? You don't have any? Add them before you start tinkering with the code ;)