[SciPy-User] line_profiler and for-loops !?

Christian Meesters meesters@gmx...
Tue Mar 16 04:16:27 CDT 2010


Hallo Sebastian,

ich kann nicht direkt auf Deine Frage antworten, weil ich weder Deinen Code noch line_profiler kenne. Aber ich habe ein C++-Modul zur Berechnung einer Abstandsverteilungsfunktion (Berechnung aller euklidischen Distanzen innerhalb einer Punktwolke). Das Modul nutzt keinerlei numpy-header (weil ich es in eine reine C++-App mal einbauen wollte) und ist mit SWIG gewrappt. Es ist rel. schnell: ca. 2x so schnell wie ein (noch mit Pyrex gebautes) Vergleichsmodul. Aber Gael sagte ja, daß Cython schneller sein kann und einfacher zu coden.

Wie auch immer: Wenn Du Interesse hast lasse ich es Dir zukommen.

Sehen wir uns in Paris?

Besten Gruß,
Christian


-------- Original-Nachricht --------
> Datum: Tue, 16 Mar 2010 09:40:14 +0100
> Von: Sebastian Haase <seb.haase@gmail.com>
> An: SciPy Users List <SciPy-user@scipy.org>
> Betreff: [SciPy-User] line_profiler and for-loops !?

> Hi,
> 
> I was starting to use Robert's line_profiler. I seems to work great,
> and I already found one easy way do half my execution time.
> But now it claims that 33% of the time is spent (directly) in the
> "for"-line and another 36% in a very simple "if"-line. See parts of
> the output here:
> <snip>
> Function: doTracing at line 1135
> Total time: 23.9171 s
> 
> Line #      Hits         Time  Per Hit   % Time  Line Contents
> ==============================================================
> <snip>
>   1185                                                       # iterate
> over all tracks, and find close points
>   1186   3853362      8024186      2.1     33.5              for
> tracki,track in enumerate(self.tracks):
>   1187   3853063      8639273      2.2     36.1                  if
> self.tracks_tLast[tracki] == t-1:
>   1188
>                   # track went on until t-1 (so far)
>   1189
>                   #    --  otherwise, skip "old" tracks
>   1190     62150       130277      2.1      0.5
>    pi_t_1 = track[-1] # index in last time section
> <snip>
> 
> (The object of the function is to connect closest points found in an
> image sequence into tracks connecting the points by shortest steps.)
> 
> Anyhow, my question is, is this just an artifact of line_profiler, or
> is the fact that those two lines are hit almost 4e6 times really
> resulting in more than 50% of the time being spent here !?
> (Calculating the actual Euclidean distance matrix over all point pairs
> takes supposedly only 15% of the time, for comparison).
> I tried to separate out the "enumerate(self.tracks)" into a separate
> line before the "for"-line, but the time spent was still unchanged on
> the "for".
> Does this mean "python is slow" here - and I should try cython (which
> i have never done so far ...) ?
> 
> Thanks,
> Sebastian Haase
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user

-- 
GMX DSL: Internet, Telefon und Entertainment für nur 19,99 EUR/mtl.!
http://portal.gmx.net/de/go/dsl02


More information about the SciPy-User mailing list