math.sqrt(x)
is significantly faster than x**0.5
.
import math
N = 1000000
%%timeit
for i in range(N):
z=i**.5
10 loops, best of 3: 156 ms per loop
%%timeit
for i in range(N):
z=math.sqrt(i)
10 loops, best of 3: 91.1 ms per loop
Using Python 3.6.9 (notebook).
More Related Contents:
- Is doing multiplication multiple times or assigning to a variable faster?
- Python OpenCV streaming from camera – multithreading, timestamps
- pandas loc vs. iloc vs. at vs. iat?
- numpy: most efficient frequency counts for unique values in an array
- Are tuples more efficient than lists in Python?
- What is the best way to generate all possible three letter strings?
- Why is [] faster than list()?
- Why is numpy’s einsum faster than numpy’s built in functions?
- What is the performance impact of non-unique indexes in pandas?
- Find out how much memory is being used by an object in Python [duplicate]
- Speed comparison with Project Euler: C vs Python vs Erlang vs Haskell
- What’s a faster operation, re.match/search or str.find?
- Cost of exception handlers in Python
- Numpy: Fix array with rows of different lengths by filling the empty elements with zeros
- Performance with global variables vs local
- Complexity of list.index(x) in Python
- Why is pow(a, d, n) so much faster than a**d % n?
- Fastest way to swap elements in Python list
- Vectorizing or Speeding up Fuzzywuzzy String Matching on PANDAS Column
- for or while loop to do something n times [duplicate]
- Python import X or from X import Y? (performance)
- What is the fastest way to output large DataFrame into a CSV file?
- How expensive are Python dictionaries to handle?
- Python List Indexing Efficiency
- Getting days since last occurence in Pandas DataFrame?
- Does python logging flush every log?
- differences between “d = dict()” and “d = {}”
- Creating a numpy array of 3D coordinates from three 1D arrays
- Split Python sequence (time series/array) into subsequences with overlap
- numpy faster than numba and cython , how to improve numba code