Exemplo n.º 1
0
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 %.2fms" % (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 %.2fms" % (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 %.2fms" % (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 %.2fms" % (len(rectangles), n, (end-start)*1000.0/N))
Exemplo n.º 2
0
 def add_video_refresh(self, region):
     #called by add_refresh_region if the video region got painted on
     #Note: this does not run in the UI thread!
     rect = self.rectangle
     if not rect:
         return
     #something in the video region is still refreshing,
     #so we re-schedule the subregion refresh:
     self.cancel_refresh_timer()
     #add the new region to what we already have:
     add_rectangle(self.refresh_regions, region)
     #do refresh any regions which are now outside the current video region:
     #(this can happen when the region moves or changes size)
     non_video = []
     for r in self.refresh_regions:
         if not rect.contains_rect(r):
             non_video += r.substract_rect(rect)
     delay = max(150, self.auto_refresh_delay)
     refreshlog("add_video_refresh(%s) rectangle=%s, delay=%ims", region,
                rect, delay)
     if non_video:
         #refresh via timeout_add so this will run in the UI thread:
         self.timeout_add(delay, self.nonvideo_refresh, non_video)
         #only keep the regions still in the video region:
         inrect = [rect.intersection_rect(r) for r in self.refresh_regions]
         self.refresh_regions = [r for r in inrect if r is not None]
     #re-schedule the video region refresh (if we have regions to fresh):
     if self.refresh_regions:
         self.refresh_timer = self.timeout_add(delay, self.refresh)
Exemplo n.º 3
0
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 %.2fms" % (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 %.2fms" % (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 %.2fms" % (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 %.2fms" % (len(rectangles), n, (end - start) * 1000.0 / N))
Exemplo n.º 4
0
    def add_video_refresh(self, window, region):
        #called by add_refresh_region if the video region got painted on
        #Note: this does not run in the UI thread!
        rect = self.rectangle
        if not rect:
            return
        refreshlog("add_video_refresh(%s, %s) rectangle=%s", window, region,
                   rect)
        #something in the video region is still refreshing,
        #so we re-schedule the subregion refresh:
        self.cancel_refresh_timer()
        #add the new region to what we already have:
        add_rectangle(self.refresh_regions, region)
        #do refresh any regions which are now outside the current video region:
        #(this can happen when the region moves or changes size)
        non_video = []
        for r in self.refresh_regions:
            if not rect.contains_rect(r):
                non_video += r.substract_rect(rect)
        delay = max(150, self.auto_refresh_delay)
        if non_video:
            #refresh via timeout_add so this will run in the UI thread:
            self.timeout_add(delay, self.refresh_cb, window, non_video)
            #only keep the regions still in the video region:
            inrect = [rect.intersection_rect(r) for r in self.refresh_regions]
            self.refresh_regions = [r for r in inrect if r is not None]
        #re-schedule the video region refresh (if we have regions to fresh):
        if self.refresh_regions:

            def refresh():
                #runs via timeout_add, safe to call UI!
                self.refresh_timer = None
                regions = self.refresh_regions
                self.refresh_regions = []
                #it probably makes sense to refresh the whole thing:
                #(the window source code doesn't know about the video region,
                # and would decide to do many overlapping refreshes)
                if len(regions) >= 2 and rect:
                    regions = [rect]
                refreshlog("refresh() calling %s with regions=%s",
                           self.refresh_cb, regions)
                self.refresh_cb(window, regions)

            self.refresh_timer = self.timeout_add(delay, refresh)
Exemplo n.º 5
0
 def add_video_refresh(self, window, region):
     #called by add_refresh_region if the video region got painted on
     #Note: this does not run in the UI thread!
     rect = self.rectangle
     if not rect:
         return
     refreshlog("add_video_refresh(%s, %s) rectangle=%s", window, region, rect)
     #something in the video region is still refreshing,
     #so we re-schedule the subregion refresh:
     self.cancel_refresh_timer()
     #add the new region to what we already have:
     add_rectangle(self.refresh_regions, region)
     #do refresh any regions which are now outside the current video region:
     #(this can happen when the region moves or changes size)
     non_video = []
     for r in self.refresh_regions:
         if not rect.contains_rect(r):
             non_video += r.substract_rect(rect)
     delay = max(150, self.auto_refresh_delay)
     if non_video:
         #refresh via timeout_add so this will run in the UI thread:
         self.timeout_add(delay, self.refresh_cb, window, non_video)
         #only keep the regions still in the video region:
         inrect = [rect.intersection_rect(r) for r in self.refresh_regions]
         self.refresh_regions = [r for r in inrect if r is not None]
     #re-schedule the video region refresh (if we have regions to fresh):
     if self.refresh_regions:
         def refresh():
             #runs via timeout_add, safe to call UI!
             self.refresh_timer = None
             regions = self.refresh_regions
             self.refresh_regions = []
             #it probably makes sense to refresh the whole thing:
             #(the window source code doesn't know about the video region,
             # and would decide to do many overlapping refreshes)
             if len(regions)>=2 and rect:
                 regions = [rect]
             refreshlog("refresh() calling %s with regions=%s", self.refresh_cb, regions)
             self.refresh_cb(window, regions)
         self.refresh_timer = self.timeout_add(delay, refresh)