def test_gvim_damage_performance(rectangles): start = time.time() for _ in range(N): rects = [] for x, y, width, height in rectangles: r = rectangle(x, y, width, height) rects.append(r) end = time.time() print("created %s rectangles %s times in %.3fms" % (len(rectangles), N, (end - start) * 1000.0 / N)) #now try add rectangle: start = time.time() for _ in range(N): rects = [] for x, y, width, height in rectangles: r = rectangle(x, y, width, height) add_rectangle(rects, r) end = time.time() print("add_rectangle %s rectangles %s times in %.3fms" % (len(rectangles), N, (end - start) * 1000.0 / N)) #now try remove rectangle: start = time.time() for _ in range(N): rects = [] for x, y, width, height in rectangles: r = rectangle(x + width // 4, y + height // 3, width // 2, height // 2) remove_rectangle(rects, r) end = time.time() print("remove_rectangle %s rectangles %s times in %.3fms" % (len(rectangles), N, (end - start) * 1000.0 / N)) start = time.time() n = N * 1000 for _ in range(n): for r in rects: contains_rect(rects, r) end = time.time() print("contains_rect %s rectangles %s times in %.3fms" % (len(rectangles), n, (end - start) * 1000.0 / N))
def remove_refresh_region(self, region): remove_rectangle(self.refresh_regions, region) remove_rectangle(self.nonvideo_regions, region) refreshlog("remove_refresh_region(%s) updated refresh regions=%s, nonvideo regions=%s", region, self.refresh_regions, self.nonvideo_regions)