Is there a faster alternative to python's Decimal?

前端 未结 5 718
野趣味
野趣味 2021-02-05 09:51

Does anyone know of a faster decimal implementation in python?

As the example below demonstrates, the standard library\'s decimal module is ~100 times slower than

5条回答
  •  爱一瞬间的悲伤
    2021-02-05 10:44

    You can try cdecimal:

    from cdecimal import Decimal
    

    As of Python 3.3, the cdecimal implementation is now the built-in implementation of the decimal standard library module, so you don't need to install anything. Just use decimal.

    For Python 2.7, installing cdecimal and using it instead of decimal should provide a speedup similar to what Python 3 gets by default.

提交回复
热议问题