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
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")