All pastes #1445937 Raw Edit

Anonymous

public python v1 · immutable
#1445937 ·published 2009-06-03 08:51 UTC
rendered paste body
#!/usr/bin/env python# -*- coding: utf-8 -*-## File: testheap.py## Author: Michael K.#### Created: Среда, Июнь  3 2009import timeimport psycopsyco.full()class Main:    global RESOLUTION    RESOLUTION = 5000    class Test1:        def iters(self, max_iter, xc, yc):            x = xc; y = yc            for count in range(max_iter):                if( x*x + y*y >= 4.0): return count                tmp = x*x-y*y+xc                y = 2.0 * x * y + yc                x = tmp            return max_iter        def run(self):            st = int(time.time())            max_val = RESOLUTION/2            min_val = -max_val            mul = 2.0 / max_val            count = 0            for i in range(min_val, max_val+1):                for j in range(min_val, max_val+1):                    count += self.iters(100,mul*i,mul*j)            print "result", count            en = int(time.time())            print "Time :", en-st                class Test2:        global Complex        class Complex :            def __init__(self, xc, yc): self.x, self.y = xc, yc            def norm_square(self): return self.x*self.x + self.y*self.y            def mul(self, other): return Complex(self.x*other.x-self.y*other.y, self.x*other.y + self.y*other.x);            def add(self, other): return Complex(self.x+other.x, self.y+other.y)        def iters(self,max_iter, xc, yc):                c = Complex(xc,yc)                z = Complex(xc,yc)                for count in range(max_iter):                    if( z.norm_square() >= 4.0 ): return count                    z = z.mul(z).add (c)                return max_iter        def run(self):            st = int(time.time())            max_val = RESOLUTION/2            min_val = -max_val            mul = 2.0 / max_val            count = 0            for i in range(min_val, max_val+1):                for j in range(min_val, max_val+1):                    count += self.iters(100,mul*i,mul*j)            print "result", count            en = int(time.time())            print "Time :", (en-st)Main().Test1().run()Main().Test2().run()