简体   繁体   中英

how to analyze cpu time while benchmarking in python (multiprocessing)?

Followings are the result after profiling using %time in ipython-

single-thread: CPU time: user 6m44s sys 1.78s total 6m46s Wall time: 5m19s

4-thread: CPU time: user 10m12s sys 2.83s total 10m15s Wall time: 4m14s

Shouldn't CPU time be lesser for multi-threaded code ? Also, how can be CPU time be more than wall time, as wall time is total elapsed time. Could you please clarify these terminology.

No CPU time is the time spent by all cpus on the task. So if cpu1 spent 2 minutes on a task and cpu2 spent 3 minutes on the same task the cpu time will be 1 + 3 = 4.

So in multithreaded programs we would expect that cpu time will usually be more than the wall time.

Now you might ask why does the same hold for your single-threaded program. The answer will probably be that even if your code does not explicitly use parallelism, there is probably a library you use that does.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM