在分析Cython代码时,`stringsource`是什么? [英] When profiling Cython Code, what is `stringsource`?

查看:54
本文介绍了在分析Cython代码时,`stringsource`是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试优化一个沉重的Cython函数.我正在按照以下教程进行配置 http://docs.cython.org/src/tutorial/profiling_tutorial.html .我的个人资料输出如下:

I have a heavy Cython function that I'm trying to optimize. I am profiling per this following tutorial http://docs.cython.org/src/tutorial/profiling_tutorial.html. My profile output looks like this:

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    7.521    7.521   18.945   18.945 routing_cython_core.pyx:674(resolve_flat_regions_for_drainage)
  6189250    4.964    0.000    4.964    0.000 stringsource:323(__cinit__)
  6189250    2.978    0.000    7.942    0.000 stringsource:618(memoryview_cwrapper)
  6009849    0.868    0.000    0.868    0.000 routing_cython_core.pyx:630(_is_flat)
  6189250    0.838    0.000    0.838    0.000 stringsource:345(__dealloc__)
  6189250    0.527    0.000    0.527    0.000 stringsource:624(memoryview_check)
  1804189    0.507    0.000    0.683    0.000 routing_cython_core.pyx:646(_is_sink)
    15141    0.378    0.000    0.378    0.000 {_gdal_array.BandRasterIONumPy}
        3    0.066    0.022    0.086    0.029 /home/rpsharp/local/workspace/invest-natcap.invest-3/invest_natcap/raster_utils.py:235(new_raster_from_base_uri)
    11763    0.048    0.000    0.395    0.000 /usr/lib/python2.7/dist-packages/osgeo/gdal_array.py:189(BandReadAsArray)

特别是我对第2行和第3行感兴趣,这些行多次调用 stringsource:323(__ cinit __) stringsource:618(memoryview_cwrapper).Google出现了对我在该函数中未使用的内存视图的引用,尽管我是静态地键入numpy数组.知道这些调用是什么,是否可以避免/优化它们?

Specifically I'm interested in lines 2 and 3 that call stringsource:323(__cinit__) and stringsource:618(memoryview_cwrapper) many times. A Google turned up references to memory views which I'm not using in that function, although I am statically typing numpy arrays. Any idea what these calls are and if I can avoid/optimize them?

推荐答案

好吧,事实证明,我 did 有一个内存视图.我正在调用一个内联函数,该函数将静态类型的numpy数组传递给了内存视图,从而调用了所有额外的对stringsource的调用.将函数调用中的memoryview类型替换为numpy类型,即可解决此问题.

Okay, turns out I did have a memory view. I was calling an inline function that passed a statically typed numpy array to a memory view, thus invoking all those extra calls to stringsource. Replacing the memoryview type in the function call with a numpy type fixed this.

这篇关于在分析Cython代码时,`stringsource`是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆