Why is repr(int) faster than str(int)?

前端 未结 3 627
深忆病人
深忆病人 2021-02-02 08:00

I am wondering why repr(int) is faster than str(int). With the following code snippet:

ROUNDS = 10000

def concat_strings_str():
    re         


        
3条回答
  •  攒了一身酷
    2021-02-02 08:32

    I just compared the str and repr implementations in the 3.5 branch. See here.

    There seems to be more checks in str:

提交回复
热议问题