官术网_书友最值得收藏!

Profiling your code

We saw in the previous example that we can individually time different functions and components with the standard time function in Python. While this approach works fine for our small example program, this won't always be feasible for larger programs that call on many different functions, some of which may or may not be worth our effort to parallelize, or even optimize on the CPU. Our goal here is to find the bottlenecks and hotspots of a programeven if we were feeling energetic and used time around every function call we make, we might miss something, or there might be some system or library calls that we don't even consider that happen to be slowing things down. We should find candidate portions of the code to offload onto the GPU before we even think about rewriting the code to run on the GPU; we must always follow the wise words of the famous American computer scientist Donald Knuth: Premature optimization is the root of all evil.

We use what is known as a profiler to find these hot spots and bottlenecks in our code. A profiler will conveniently allow us to see where our program is taking the most time, and allow us to optimize accordingly.

主站蜘蛛池模板: 广宗县| 大同市| 梁河县| 洱源县| 庄河市| 天镇县| 瑞金市| 铁岭县| 全椒县| 图木舒克市| 万山特区| 鲜城| 保康县| 平顶山市| 嘉祥县| 大港区| 镇原县| 玛曲县| 湖南省| 虹口区| 宜都市| 麦盖提县| 榆林市| 读书| 丹阳市| 江安县| 岚皋县| 伊金霍洛旗| 博客| 桐乡市| 南岸区| 白银市| 静海县| 措勤县| 临汾市| 乌鲁木齐市| 中阳县| 区。| 电白县| 巴彦淖尔市| 水富县|