def timeTrial(n): a = stdarray.create1D(n, 0) for i in range(n): a[i] = stdrandom.uniformInt(-1000000, 1000000) watch = Stopwatch() count = threesum.countTriples(a) return watch.elapsedTime()
def timeTrials(f, n, trials): total = 0.0 a = stdarray.create1D(n, 0.0) for t in range(trials): for i in range(n): a[i] = stdrandom.uniformFloat(0.0, 1.0) watch = Stopwatch() f(a) total += watch.elapsedTime() return total
n = 512 xc = -.5 yc = 0 size = 2 w1 = Stopwatch() pic = Picture(n, n) for col in range(n): for row in range(n): x0 = xc - (size / 2) + (size * col / n) y0 = yc - (size / 2) + (size * row / n) z0 = complex(x0, y0) gray = MAX - mandel(z0, MAX) color = Color(gray, gray, gray) pic.set(col, n - 1 - row, color) print(w1.elapsedTime()) w2 = Stopwatch() pic = Picture(n, n) for col in range(n): for row in range(n): x0 = xc - (size / 2) + (size * col / n) y0 = yc - (size / 2) + (size * row / n) #z0 = [x0,y0] gray = MAX - mandel1(x0, y0, MAX) color = Color(gray, gray, gray) pic.set(col, n - 1 - row, color) print(w2.elapsedTime()) stddraw.setCanvasSize(n, n) stddraw.picture(pic)