Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news-1.dfn.de!news.dfn.de!fu-berlin.de!uni-berlin.de!news.dfncis.de!not-for-mail From: Helmut Jarausch Newsgroups: comp.lang.python Subject: Re: How to make this faster Date: 5 Jul 2013 10:07:57 GMT Lines: 34 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: news.dfncis.de 8jjPf3ihcjBYH/fmwxN6YQWyKmmDE0beem6d440HkmltpB/XksLS4tfrAI Cancel-Lock: sha1:+uce89oI+REhwYAMjx5ajkCL0dQ= User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508 git://git.gnome.org/pan2) Xref: csiph.com comp.lang.python:49959 On Fri, 05 Jul 2013 10:38:35 +0100, Fábio Santos wrote: > [Skipping to bottleneck] > >> def find_good_cell() : > > In this function you are accessing global variables a lot of times. Since > accessing globals takes much more time than accessing locals, I advise you > to assign them to local names, and use them. I've tried to use local "references" like G= Grid and using G instead of Grid below and similarly for Row_Digits, Col_Digits and Sqr_Digits but it had no noticeable effect. > >> Best= None >> minPoss= 10 >> for r in range(9) : >> for c in range(9) : >> if Grid[r,c] > 0 : continue >> Sq_No= (r//3)*3+c//3 >> Possibilities= 0 >> for d in range(1,10) : > > On this condition (below) you can try to check which condition is True more > often and put that condition first in order to take advantage of short > circuiting and minimize array access. Unfortunately, that's unpredictable. > >> if Row_Digits[r,d] or Col_Digits[c,d] or Sqr_Digits[Sq_No,d] : > continue Many thanks, Helmut