# HG changeset patch # User Eugen Sawin # Date 1276386838 -7200 # Node ID 0ebb73fd094aa4e27075fb0b6eff0d7b33c9253e # Parent a99535269d6062ee521589fd21c09425042c2b15 Profiling added. diff -r a99535269d60 -r 0ebb73fd094a algorithm.py --- a/algorithm.py Sun Jun 13 00:18:09 2010 +0200 +++ b/algorithm.py Sun Jun 13 01:53:58 2010 +0200 @@ -1,6 +1,22 @@ -def isDivergent(f): - if f == float("inf") or f == float("-inf"): +import time + +def profile(func): + def wrapper(*arg): + t1 = time.clock() + res = func(*arg) + t2 = time.clock() + print "duration: %fs" % float(t2-t1) + return res + return wrapper + +def isDivergent(c): + if c.real == float("inf") or c.real == float("-inf"): return True + if c.imag == float("inf") or c.imag == float("-inf"): + return True + return False + +def isPeriodic(z): return False class Cell(object): @@ -19,10 +35,12 @@ z = [0] for i in xrange(max_iter): z.append(self.iterate(z[-1], c)) - if isDivergent(z[-1].real) or isDivergent(z[-1].imag): + if isDivergent(z[-1]): + break + if isPeriodic(z[-10:-1]): break return z - + @profile def resolve(self, max_iter): cells = {} x_diff = (self.range[1].real - self.range[0].real) / self.resolution[0] @@ -32,8 +50,8 @@ for y in xrange(self.resolution[1]): for x in xrange(self.resolution[0]): c = self.range[0] + c_diff * complex(x, y) - print c - print self.test(c, max_iter) + #print c + #print self.test(c, max_iter)