[issue32880] IDLE: Fix and update and cleanup pyparse

Cheryl Sabella report at bugs.python.org
Sat Feb 24 13:56:45 EST 2018


Cheryl Sabella <chekat2 at gmail.com> added the comment:

I wish I could delete my last message (and duplicate posting of the one before.  On the last one, I didn't move my timings.  I feel like an idiot.  Anyway, there is a difference.
```
start = time.time()
for i in range(1000000):
    _tran = defaultdict(lambda: 'x')
    _tran.update((ord(c), ord('(')) for c in "({[")
    _tran.update((ord(c), ord(')')) for c in ")}]")
    _tran.update((ord(c), ord(c)) for c in "\"'\\\n#")
end = time.time()
print(f'translate time: {end - start}')
```
translate time: 7.443669319152832

```
start = time.time()
for i in range(1000000):
    _tran = defaultdict(lambda: 'x')
    _tran.update({40: 40,    # ord('(')
                  91: 40,    # ord('[')
                  123: 40,   # ord('{')
                  41: 41,    # ord(')')
                  93: 41,    # ord(']')
                  125: 41,   # ord('}')
                  34: 34,    # ord('"')
                  39: 39,    # ord("'")
                  92: 92,    # ord("\\")
                  10: 10,    # ord("\n")
                  35: 35,    # ord("#")
                  })
end = time.time()
print(f'translate time: {end - start}')
```
translate time: 1.7251780033111572

It's still probably negligible since it's only done once and not a million times.  :-)

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32880>
_______________________________________


More information about the Python-bugs-list mailing list