# str(bigint) is slow

Delaney, Timothy C (Timothy) tdelaney at avaya.com
Fri Jul 9 08:34:03 CEST 2004

```Bryan wrote:

> does anyone know how to make this faster?  it seems that str(x) is
> the slow part.
>
>
>  >>> def foo():
> ...     t1 = time.time()
> ...     x = 19 ** 314159
> ...     t2 = time.time()
> ...     y = str(x)
> ...     t3 = time.time()
> ...     print y
> ...     t4 = time.time()
> ...     print t2-t1, t3-t2, t4-t3
> ...
>  >>> foo()
> <snip a print out of a billion numbers>
> 3.78499984741 230.490999937 0.0700001716614
Bryan wrote:

> does anyone know how to make this faster?  it seems that str(x) is
> the slow part.
>
>  >>> def foo():
> ...     t1 = time.time()
> ...     x = 19 ** 314159
> ...     t2 = time.time()
> ...     y = str(x)
> ...     t3 = time.time()
> ...     print y
> ...     t4 = time.time()
> ...     print t2-t1, t3-t2, t4-t3
> ...
>  >>> foo()
> <snip a print out of a billion numbers>
> 3.78499984741 230.490999937 0.0700001716614

401732 digits actually ... that's not even half a million ...

There was a recent thread titled "How to get decimal form of largest
known prime?" ...

http://tinyurl.com/3b2no