You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using native operators is faster but not that faster. These are my results when *_2 and *_0.5 are replaced in the source code of clustering.py
%time python2.7 main.py > k-means-result.txt
python2.7 main.py > k-means-result.txt 22.45s user 0.14s system 99% cpu 22.610 total
This is the version where only math.pow is replaced with native operators:
%time python2.7 main.py > k-means-result_FAST.txt
python2.7 main.py > k-means-result_FAST.txt 19.85s user 0.14s system 99% cpu 20.001 total
This is the version where both math.pow and math.sqrt are replaced:
[veleno@irmbp:k-means]%time python2.7 main.py > k-means-result_FASTER.txt
python2.7 main.py > k-means-result_FASTER.txt 19.76s user 0.15s system 99% cpu 19.929 total
Rather than using
math
functions (such asmath.sqrt
andmath.pow
) to calculate euclidean distance, use the builtin operators:x**2
andx**0.5
The code object disassembly shows fewer instructions in the latter:
This can also be empirically show by the
timeit
results:Using the operators is about 75% faster.
The text was updated successfully, but these errors were encountered: