Last active
November 17, 2017 22:41
-
-
Save kozzztik/32602f82be7ff70fc6ec5fd552fd5021 to your computer and use it in GitHub Desktop.
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
import time | |
def func1(param): | |
counter = 0 | |
while param: | |
if param & 1: | |
counter += 1 | |
param >>= 1 | |
return counter | |
def func2(param): | |
return bin(param).count('1') | |
val = 4242424242 | |
count = 100000 | |
print('C like') | |
t1 = time.time() | |
print(sum(map(func1, range(val, val + count)))) | |
print(time.time() - t1) # 0.778 | |
print('bin') | |
t1 = time.time() | |
print(sum(map(func2, range(val, val + count)))) | |
print(time.time() - t1) # 0.100 | |
print('bin + join') | |
t1 = time.time() | |
print(''.join(map(bin, range(val, val + count))).count('1')) | |
print(time.time() - t1) # 0.053 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment