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

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.

主站蜘蛛池模板: 新竹市| 东安县| 闽清县| 普陀区| 枣庄市| 鹤岗市| 建瓯市| 新野县| 当涂县| 邯郸市| 蒲城县| 福泉市| 岳阳市| 顺昌县| 班玛县| 潞西市| 洛扎县| 余江县| 长子县| 神木县| 体育| 黄龙县| 肥西县| 环江| 枣阳市| 大兴区| 仙游县| 田林县| 呼伦贝尔市| 本溪市| 会同县| 呼图壁县| 蓝山县| 武功县| 泾阳县| 汝阳县| 江川县| 洪洞县| 昆山市| 邵阳市| 凯里市|