Felhasználói eszközök

Eszközök a webhelyen


tudasbazis:programozas:python:teljesitmeny_teszt

Összehasonlítás

A kiválasztott és az jelenlegi változat között az alábbi különbségek fordulnak elő:

Összehasonlító nézet hivatkozása

tudasbazis:programozas:python:teljesitmeny_teszt [2015.05.12 17:34] – külső szerkesztés 127.0.0.1tudasbazis:programozas:python:teljesitmeny_teszt [2015.10.13 13:32] (aktuális) – tia
Sor 1: Sor 1:
 +====== Teljesítmény teszt ======
 +  * http://stackoverflow.com/questions/24791251/install-pyyaml-using-pip-add-pyyaml-as-pip-dependency/24791419#24791419
 +  * http://www.huyng.com/posts/python-performance-analysis/
 +  * https://docs.python.org/3.4/library/tracemalloc.html
  
 +
 +===== Futás idő =====
 +  - Függőségek telepítése: <code bash>
 +pip install line_profiler
 +</code>
 +  - Dekoráljuk meg a tesztelendő függvényeket ''@profile'' dekorátorral
 +  - Indítsuk el speciálisan: <code bash>
 +kernprof -l script_to_profile.py
 +</code>
 +  - Nézzük meg az eredményt: <code bash>
 +python -m line_profiler script_to_profile.py.lprof
 +</code><file>
 +Pystone(1.1) time for 50000 passes = 2.48
 +This machine benchmarks at 20161.3 pystones/second
 +Wrote profile results to pystone.py.lprof
 +Timer unit: 1e-06 s
 +
 +File: pystone.py
 +Function: Proc2 at line 149
 +Total time: 0.606656 s
 +
 +Line #      Hits         Time  Per Hit   % Time  Line Contents
 +==============================================================
 +   149                                           @profile
 +   150                                           def Proc2(IntParIO):
 +   151     50000        82003      1.6     13.5      IntLoc = IntParIO + 10
 +   152     50000        63162      1.3     10.4      while 1:
 +   153     50000        69065      1.4     11.4          if Char1Glob == 'A':
 +   154     50000        66354      1.3     10.9              IntLoc = IntLoc - 1
 +   155     50000        67263      1.3     11.1              IntParIO = IntLoc - IntGlob
 +   156     50000        65494      1.3     10.8              EnumLoc = Ident1
 +   157     50000        68001      1.4     11.2          if EnumLoc == Ident1:
 +   158     50000        63739      1.3     10.5              break
 +   159     50000        61575      1.2     10.1      return IntParIO
 +</file>
 +
 +
 +===== Memória =====
 +  - Függőségek telepítése: <code bash>
 +pip install -U memory_profiler
 +pip install psutil
 +</code>
 +  - Dekoráljuk meg a tesztelendő függvényeket ''@profile'' dekorátorral
 +  - Indítsuk el speciálisan: <code bash>
 +python -m memory_profiler primes.py
 +</code> <code>
 +Filename: primes.py
 +
 +Line #    Mem usage  Increment   Line Contents
 +==============================================
 +     2                           @profile
 +     3    7.9219 MB  0.0000 MB   def primes(n): 
 +     4    7.9219 MB  0.0000 MB       if n==2:
 +     5                                   return [2]
 +     6    7.9219 MB  0.0000 MB       elif n<2:
 +     7                                   return []
 +     8    7.9219 MB  0.0000 MB       s=range(3,n+1,2)
 +     9    7.9258 MB  0.0039 MB       mroot = n ** 0.5
 +    10    7.9258 MB  0.0000 MB       half=(n+1)/2-1
 +    11    7.9258 MB  0.0000 MB       i=0
 +    12    7.9258 MB  0.0000 MB       m=3
 +    13    7.9297 MB  0.0039 MB       while m <= mroot:
 +    14    7.9297 MB  0.0000 MB           if s[i]:
 +    15    7.9297 MB  0.0000 MB               j=(m*m-3)/2
 +    16    7.9258 MB -0.0039 MB               s[j]=0
 +    17    7.9297 MB  0.0039 MB               while j<half:
 +    18    7.9297 MB  0.0000 MB                   s[j]=0
 +    19    7.9297 MB  0.0000 MB                   j+=m
 +    20    7.9297 MB  0.0000 MB           i=i+1
 +    21    7.9297 MB  0.0000 MB           m=2*i+3
 +    22    7.9297 MB  0.0000 MB       return [2]+[x for x in s if x]
 +</code>
 +
 +
 +===== Leak keresés =====
 +  - Függőségek telepítése: <code bash>
 +pip install objgraph
 +</code>
 +  - Kód megállítása ''pdb''-vel
 +  - A jelenleg memóriában lévő objektumokról riport kérése: <code python>
 +import objgraph
 +objgraph.show_most_common_types()
 +</code> <code>
 +MyBigFatObject             20000
 +tuple                      16938
 +function                   4310
 +dict                       2790
 +wrapper_descriptor         1181
 +builtin_function_or_method 934
 +weakref                    764
 +list                       634
 +method_descriptor          507
 +getset_descriptor          451
 +type                       439
 +</code>
 +  - Függőségi gráf generálása: <code python>
 +objgraph.show_backref([x], filename="/tmp/backrefs.png")
 +</code>