Last active
May 22, 2018 19:22
-
-
Save joonro/3ceb590ac9d616cbaf19 to your computer and use it in GitHub Desktop.
[Loop speed test] #python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def summation(arg): | |
return_val = 0 | |
for i in arg: | |
return_val += i | |
return(return_val) | |
test_range = np.arange(10) | |
%timeit summation(test_range) | |
100000 loops, best of 3: 2.22 µs per loop | |
%timeit test_range.sum() | |
100000 loops, best of 3: 2.45 µs per loop | |
test_range = np.arange(100) | |
%timeit summation(test_range) | |
%timeit test_range.sum() | |
100000 loops, best of 3: 13.4 µs per loop | |
100000 loops, best of 3: 2.45 µs per loop | |
test_range = np.arange(1000) | |
%timeit summation(test_range) | |
10000 loops, best of 3: 122 µs per loop | |
%timeit test_range.sum() | |
100000 loops, best of 3: 3.03 µs per loop | |
test_range = np.arange(10000) | |
%timeit summation(test_range) | |
1000 loops, best of 3: 1.24 ms per loop | |
%timeit test_range.sum() | |
100000 loops, best of 3: 6.59 µs per loop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment