Inada Naoki <[email protected]> added the comment:
I added _PyDict_FromItems() to the PR.
It checks that all keys are Unicode or not before creating dict.
_PyDict_NewPresized() just returns general-purpose dict. But it isn't used from
CPython core. It is just kept for compatibility (for Cython).
```
$ ./python -m pyperf timeit --compare-to ../cpython/python -- '{"k1":1, "k2":2,
"k3":3, "k4":4, "k5":5, "k6":6}'
/home/inada-n/work/python/cpython/python: ..................... 198 ns +- 5 ns
/home/inada-n/work/python/dict-compact/python: ..................... 213 ns +-
6 ns
Mean +- std dev: [/home/inada-n/work/python/cpython/python] 198 ns +- 5 ns ->
[/home/inada-n/work/python/dict-compact/python] 213 ns +- 6 ns: 1.07x slower
```
Overhead of checking keys types is not so large.
Additionally, we can reduce some code from ceval.c.
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue46845>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com