0

My PyQt5 Project. A simple button clicked event do some printing and capture the execution time.

The problem is, each time I click the button, the execution time increase as compared to previous cycle. Any idea what is the cause?

These are the execution time result:

Cycle 1: 3.027s

Cycle 2: 3.302

Cycle 3: 3.594

Cycle 4: 3.848

I am running on Windows 10, Python 3.8.8, PyQt5 5.15.1

class MainWindow(QtWidgets.QMainWindow):
    def __init__(self):

        super(MainWindow, self).__init__()
        uic.loadUi("./package/ui/MainWindow.ui", self)
        


        
        #==============================Form loaded===============================     
        

        self.button_Test.clicked.connect(self.button_Test_Clicked)

    def button_Test_Clicked(self):
        print("button clicked")
        print(colorama.ansi.clear_screen())
        self.start_time = time.time()
        y = 0
        for x in range (0, 30000):
            y = x * 2
            print(y)

        print(y)
        self.elapse_time = time.time() - self.start_time
        print("Test Execution time = " + str(self.elapse_time))  
kjying
  • 1
  • I run the exact same code in ubuntu dont have this issue. the execution time remains the same even after numerous cycle. – kjying Mar 04 '21 at 13:52
  • You should test with [timeit](https://docs.python.org/3/library/timeit.html#module-timeit) so as to [avoid inaccuracies](https://stackoverflow.com/q/17579357/984421). You should also remove the print statements, unless that is what you are trying to measure. – ekhumoro Mar 04 '21 at 16:15

0 Answers0