Last active
October 25, 2020 04:54
-
-
Save ychevarrias/9efc21c4cc9a518a46bfd8b472ad782a to your computer and use it in GitHub Desktop.
Py brench
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
from uuid import uuid4 | |
import time | |
def get_bin_str(_bytes): | |
return " ".join( | |
["{0:08b}".format(bit) for bit in _bytes] | |
) | |
def get_uuid_humanized(): | |
uid = uuid4() | |
return "{} -> {}".format( | |
uid.hex, get_bin_str(uid.bytes[:8]) | |
) | |
counter = 0 | |
transcurred = 0 | |
start_time = time.time() | |
while transcurred < 10: | |
counter += 1 | |
value = get_uuid_humanized() | |
print(value, end="\r" if counter % 1000 else f' -> {counter}\n') | |
transcurred = time.time() - start_time | |
print(f"\n\nExec {counter} in {transcurred}") | |
# Results with prints | |
# Linux -> Exec 374649 in 10.000030994415283 | |
# Win2 -> Exec 133001 in 10.00014352798462 | |
# WSL -> Exec 103809 in 10.00002408027649 | |
# Results without prints | |
# Linux -> Exec 1030756 in 10.000000238418579 | |
# Win2 -> Exec 830500 in 10.00093817710876 | |
# WSL -> Exec 631950 in 10.00000786781311 | |
# Results without prints Ryzen 5 3600 | |
# Linux -> Exec 1030756 in 10.000000238418579 | |
# Win2 -> Exec 1628630 in 10.00093817710876 | |
# WSL -> Exec 1379373 in 10.00000786781311 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have this error:
Traceback (most recent call last):
File "brench.py", line 33, in
result = timeit.repeat('bench.bench()', setup='import bench', number=10, repeat=10)
File "/usr/lib/python3.8/timeit.py", line 237, in repeat
return Timer(stmt, setup, timer, globals).repeat(repeat, number)
File "/usr/lib/python3.8/timeit.py", line 204, in repeat
t = self.timeit(number)
File "/usr/lib/python3.8/timeit.py", line 176, in timeit
timing = self.inner(it, self.timer)
File "", line 3, in inner
ModuleNotFoundError: No module named 'bench'