slightly speedup Basic.__getattr__
authorKirill Smelkov <kirr@landau.phys.spbu.ru>
Mon Mar 24 01:19:27 2008 +0300 (2 years ago)
changeset 103475544c92be1d
parent 1033115df7b1ee75
child 103595b5af645143
slightly speedup Basic.__getattr__

Timings
-------

s = 'is_integer'
t = 'hello world'

s[:3] == 'is_' 1.17 µs
s.startswith('is_') 1.96 µs

t[:3] == 'is_' 1.13 µs
t.startswith('is_') 1.99 µs
sympy/core/basic.py
       1 --- a/sympy/core/basic.py	Mon Mar 24 00:17:14 2008 +0300
       2 +++ b/sympy/core/basic.py	Mon Mar 24 01:19:27 2008 +0300
       3 @@ -208,7 +208,7 @@
       4  
       5      def __getattr__(self, name):
       6          # if it's not an assumption -- we don't have it
       7 -        if not name.startswith('is_'):
       8 +        if name[:3] != 'is_':
       9              # it is important to return shortly for speed reasons:
      10              # we have *lots* of non-'is_' attribute access, e.g.
      11              # '_eval_<smth>', and a lot of them does *not* exits.
      12 @@ -217,7 +217,8 @@
      13              # so let's get out of here as fast as possible.
      14              raise AttributeError(name)
      15  
      16 -        return self._get_assumption(name)
      17 +        else:
      18 +            return self._get_assumption(name)
      19  
      20      # NB: there is no need in protective __setattr__
      21