CPU Utlization is Zero

Hi,
I am doing sorting with 1000 elements but my CPU utilization is still zero:

def systeminfo(self):
        print("memory usage=", psutil.Process(os.getpid()).memory_info()[0])
        print(psutil.disk_usage('/'))
        print(psutil.Process(os.getpid()).cpu_percent(interval=1))
        print("virtual mem= ", psutil.virtual_memory().available)
        # print(psutil.Process(os.getpid()).memory_info().pfaults)
        print("rss=", psutil.Process(os.getpid()).memory_info().rss)
        self.selectionSort()
        print(psutil.Process(os.getpid()).cpu_percent(interval=1))


    def main(self):
        self.generate1000_5digit_RandomNum()
        self.systeminfo()
        
    if __name__ == "__main__":
    objSSSort = SSSort(1000)
    objSSSort.main()
   

memory usage= 15269888
sdiskusage(total=982900588544, used=141417086976, free=791483416576, percent=15.2)
0.0
virtual mem= 12050067456
rss= 15269888
(0, 10000)

Somebody please guide me.

Zulfi.

The cpu percentage you’re seeing is a snapshot of current usage. If you want cumulative usage, you want the time command in your shell, and you can rip out all that psutil stuff.

Also, sorting a list of a thousand numbers is going to be nearly instantaneous on modern machines. Try at least a million.

Hi,

you want the time command in your shell, and you can rip out all that psutil stuff

Can I do it using Pycharm? or this must be done in DOS shell?

Zulfi.

You’d do it in a linux or Mac shell. You can try git bash, but it’s unlikely to collect the process accounting info. You’re probably just out of luck on windows.