[Python-ideas] Change magic strings to enums
Ivan Levkivskyi
levkivskyi at gmail.com
Wed Apr 25 06:15:42 EDT 2018
On 25 April 2018 at 11:03, Serhiy Storchaka <storchaka at gmail.com> wrote:
> 25.04.18 10:57, Ivan Levkivskyi пише:
>
>> On 25 April 2018 at 06:03, INADA Naoki <songofacandy at gmail.com <mailto:
>> songofacandy at gmail.com>> wrote:
>> enum class&member creation cost is much heavier than "import enum"
>> cost.
>> Especially, "import socket, ssl" is much slower than before...
>>
>> Is it slow simply because we are creating new class objects or
>> EnumMeta.__new__ does
>> some extensive calculations? In the latter case rewriting EnumMeta in C
>> might help.
>>
>
> Creating a new function is very cheap -- just around 50 ns on my computer.
>
> Creating a new class is over two orders costly -- around 7 us for an empty
> class on my computer.
>
> Creating a new Enum class is much more costly -- around 40 us for an empty
> class (or 50 us for IntEnum) plus 7 us per member.
>
>
Hm, this is what I wanted to know. I think by rewriting EnumMeta in C we
can reduce the creation time of an Enum class
(almost) down to the creation time of a normal class, which may be a 4-5x
speed-up. What do you think?
--
Ivan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180425/25d72545/attachment.html>
More information about the Python-ideas
mailing list