Trying to timeit my sqrt function in Python
Question: So I've tried to code a simple square root function. I did, and I wanted to
compare it with Python's original one. Here's my code:

    
    
    from math import sqrt
    import timeit
    
    def sqrt2(number):
        i=1
        while i**2<number:
            i+=1
        left=float(i-1)
        right=float(i)
        temp = left+(right-left)/2
        while str(temp**2)!=str(number):
            if temp**2>number:
                right=temp
                temp = left+(right-left)/2
            elif temp**2<number:
                left=temp
                temp = left+(right-left)/2
            else:
                return temp
        return temp
    
    print timeit.timeit("sqrt2(12)", number=10000, setup='from __main__ import sqrt2')
    print timeit.timeit("sqrt(12)", number=10000, setup='from math import sqrt')
    

It simply takes the number and notices when and integer^2 is lower and when
(integer+1)^2 is higher than our number, then divides the gap between those 2
by 2, and tries the middle number, etc. It's ok for me, but when I try to
timeit.timeit it just stops, cursor in console shows, that it's still working,
but nothing happens


Answer: As mentioned in the comments, the issue is that you get in an infinite loop
here: `while str(temp**2)!=str(number):`

Your problem is that `temp**2` in a `float`, while `number` is an `int`. Since
you compare their string representation, the first one will be, for example,
`12.0`, and the second one, `12`.

You can either fix the condition in your `while` loop (using `str()` seems
very odd indeed), or pass a `float` to your function.

And by the way, your implementation is very slow. A quick run with a float
returns:

Yours: `0.461127996445`

python's: `0.000571012496948`

