Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python Process time always returning a huge number even though it runs like normal?

Here is the code.

import time
from multiprocessing import Process, cpu_count

def counter(num):
    count = 0
    while count< num:
        count +=1


def main():
    a = Process(target=counter, args=(100000000,))
    a.start()

    a.join()

    print("finished in", time.perf_counter(), "seconds")





if __name__ ==  '__main__':
    main()

This is the return in the terminal.

finished in 808748.985729608 seconds

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The program is completed in around 4 to 5 secs but returns this huge number every time?
Could someone help explain if I Did something wrong or a setting that may need to be changed. It is on a Mac if that matters.

>Solution :

You have to capture a start time and and end time and subtract. The number by itself is meaningless (something like time since the OS booted):


start = time.perf_counter()
a.start()
a.join()
print("finished in", time.perf_counter() - start, "seconds")

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading