Check computer processing speed with a simple Python script

I want to make a simple script to check the time that the computer takes to execute it. I already built it with PyQt and made a curious loop using QTimer. Now I need to "do" part. What commands can I use only to make the computer work a little, so that I can find the time and compare with other computers?

Here is my code so you can better understand:

self.Tempo = QtCore.QTimer(None) self.Cron = QtCore.QTime(0,0,0,0) def begin(): self.Cron.start() self.Tempo.singleShot(999, update) def update(): if self.lcdNumber.value() == 10: finish() else: self.lcdNumber.display(self.lcdNumber.value()+1) #Here I want to make some processing stuff self.Tempo.singleShot(999, update) def finish(): print("end") took = self.Cron.elapsed() / 1000 print("took: {0} seconds" .format(str(took))) self.lcdNumber_2.display(took) 
+4
source share
3 answers

You can perform any complex calculation task in a cycle:

  • Calculate factorial for some large number (easy to implement)
  • Compute chain SHA1 hash 100,000 times (very easy to implement)
  • Invert a large matrix (not so easy to implement)
  • ...
  • and etc.

Some of these problems use the CPU (factorial, SHA1), some others use the processor and memory (matrix inversion). So first you need to decide which part of the computer you want to compare.

+3
source

You can usually achieve this with a loop that does some simple work, something like this:

 lst = [] for i in range(1000000): lst.append('x') 
+1
source

Instead of adding some item to the list, you can add lines. I think string concatenation is more expensive, the more lines, the better, to check the performance of your memory.

 test = "a test string" for i in range(your_value): # it takes forever, so choose this value wisely! if len(test) < 200000000: # somewhere above this limit I get errors test += test else: test = test[0:len(test)/2] # if the string gets too long just cut it. 
+1
source

Source: https://habr.com/ru/post/1383882/


All Articles