vrtulka23/scinumtools

Improve performance of unit module

vrtulka23 opened this issue · 0 comments

Too much time is being spend by calling following functions (cProfile/pstats).
Especially fraction.py and dimensions.py should be rewritten in a way so that they don't need post_init checking, because they are called the most.

  Ordered by: internal time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
     3333    0.038    0.000    0.060    0.000 /home/ubuntu/environment/scinumtools/src/scinumtools/units/fraction.py:13(__post_init__)
    25122    0.019    0.000    0.019    0.000 {built-in method builtins.isinstance}
      404    0.013    0.000    0.054    0.000 /home/ubuntu/environment/scinumtools/src/scinumtools/units/dimensions.py:21(__post_init__)
    14948    0.011    0.000    0.011    0.000 {method 'endswith' of 'str' objects}
      101    0.011    0.000    0.021    0.000 /home/ubuntu/environment/scinumtools/src/scinumtools/units/unit_solver.py:73(<listcomp>)
     3333    0.009    0.000    0.009    0.000 /home/ubuntu/environment/scinumtools/src/scinumtools/units/fraction.py:51(reduce)
    10688    0.008    0.000    0.008    0.000 {built-in method builtins.getattr}
      200    0.008    0.000    0.023    0.000 /home/ubuntu/.local/lib/python3.10/site-packages/numpy/lib/arraysetops.py:524(in1d)
     3333    0.007    0.000    0.067    0.000 <string>:2(__init__)
      200    0.005    0.000    0.009    0.000 /home/ubuntu/.local/lib/python3.10/site-packages/numpy/lib/arraysetops.py:323(_unique1d)
      101    0.004    0.000    0.048    0.000 /home/ubuntu/environment/scinumtools/src/scinumtools/solver/solver.py:48(solve)
      101    0.003    0.000    0.028    0.000 /home/ubuntu/environment/scinumtools/src/scinumtools/units/dimensions.py:48(__add__)
      909    0.003    0.000    0.005    0.000 /home/ubuntu/environment/scinumtools/src/scinumtools/solver/solver.py:77(<listcomp>)
      100    0.003    0.000    0.005    0.000 /home/ubuntu/environment/scinumtools/src/scinumtools/units/unit_types.py:17(convert)
      101    0.003    0.000    0.155    0.002 /home/ubuntu/environment/scinumtools/src/scinumtools/units/base_units.py:50(__init__)
      808    0.003    0.000    0.019    0.000 /home/ubuntu/environment/scinumtools/src/scinumtools/units/fraction.py:70(__add__)
      808    0.002    0.000    0.019    0.000 /home/ubuntu/environment/scinumtools/src/scinumtools/units/fraction.py:80(__mul__)
      101    0.002    0.000    0.033    0.000 /home/ubuntu/environment/scinumtools/src/scinumtools/units/unit_solver.py:54(AtomParser)
      100    0.002    0.000    0.004    0.000 /home/ubuntu/environment/scinumtools/src/scinumtools/units/dimensions.py:78(__eq__)
      101    0.002    0.000    0.026    0.000 /home/ubuntu/environment/scinumtools/src/scinumtools/units/dimensions.py:66(__mul__)