Integer: optionally collect info about objects creations and cache hit/miss
commit45784fed84ab1e1707f5b3ee87f13ffaba5650b3
authorKirill Smelkov <kirr@landau.phys.spbu.ru>
Tue, 26 Aug 2008 17:11:46 +0000 (26 21:11 +0400)
committerKirill Smelkov <kirr@landau.phys.spbu.ru>
Tue, 26 Aug 2008 17:11:46 +0000 (26 21:11 +0400)
tree70a8ca9c8677addf5f55a8770d0a4d7735d4bd85
parent3c4a0cf41ea56b860e9f1523878529271635374c
Integer: optionally collect info about objects creations and cache hit/miss

This is turned off by default an in no way affect runtime performance
when turned off.

When this mode is on, we'll see how effective _intcache was for a
particular workload, e.g.:

    $ SYMPY_TRACE_INT=yes ./examples/fem_test.py
    ⎡ 1/60     0    -1/360    0    -1/90  -1/360⎤
    ⎢                                           ⎥
    ⎢  0     4/45     0     2/45   2/45   -1/90 ⎥
    ⎢                                           ⎥
    ⎢-1/360    0     1/60   -1/90    0    -1/360⎥
    ⎢                                           ⎥
    ⎢  0     2/45   -1/90   4/45   2/45     0   ⎥
    ⎢                                           ⎥
    ⎢-1/90   2/45     0     2/45   4/45     0   ⎥
    ⎢                                           ⎥
    ⎣-1/360  -1/90  -1/360    0      0     1/60 ⎦

    Integer cache statistic
    -----------------------

    #items: 81

     #hit   #miss               #total

     4261      78 (1.79765 %)    4339

    [-80, -73, -72, -64, -60, -57, -56, -49, -48, -47, -40, -39, -36,
     -34, -32, -30, -28, -26, -25, -24, -21, -20, -19, -18, -16, -14,
     -13, -12, -11, -10,  -8,  -7,  -6,  -5,  -4,  -3,  -2,  -1,   0,
       1,   2,   3,   4,   5,   6,   7,   8,   9,  10,  11,  12,  13,
      14,  15,  16,  18,  19,  20,  21,  24,  26,  28,  29,  30,  31,
      32,  34,  36,  39,  40,  44,  47,  48,  49,  54,  57,  64,  66,
      72,  80,  85]

Another example:

    $ SYMPY_TRACE_INT=yes ./bin/isympy

    In [1]: integrate(x**3*sin(x), x)
    Out[1]:
                 3             2
    -6⋅sin(x) - x ⋅cos(x) + 3⋅x ⋅sin(x) + 6⋅x⋅cos(x)

    In [2]:
    Exiting ...

    Integer cache statistic
    -----------------------

    #items: 46

     #hit   #miss               #total

    14977      43 (0.28628 %)   15020

    [-24, -6, -5, -4, -3, -2, -1,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9,
      10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
      27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38]

Initially I wrote this to demonstrate that caching Integers is
important, but later I thought that maybe we'll better have it in SymPy
and gradually generalize tracing into its own subsystem.

  **************************************
  * Special thanks to Sebastian Kreft! *
  **************************************

Sebastian, good questions are already part of an answer. Please ask them more
-- we need this stuff in SymPy to look at the system from different points of
view -> to improve it.

More question and more patches are welcome!
Thanks beforehand.

Signed-off-by: Kirill Smelkov <kirr@landau.phys.spbu.ru>
Signed-off-by: Ondrej Certik <ondrej@certik.cz>
sympy/core/numbers.py