Last active
November 14, 2021 03:36
-
-
Save oconnor663/f146fb32d0065ffd48aa3ef85f0a0fb2 to your computer and use it in GitHub Desktop.
windows scripts
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
. |
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
#! /usr/bin/env python3 | |
import sys | |
import secrets | |
import time | |
import subprocess | |
assert len(sys.argv) >= 2 | |
start = time.perf_counter() | |
with open(sys.argv[1], "rb") as f: | |
file_size = f.seek(0, 2) | |
subprocess.run(["b3sum", *sys.argv[1:]], check=True) | |
end = time.perf_counter() | |
gb = file_size / 1_000_000_000 | |
duration = end - start | |
if duration == 0: | |
print(f"read {file_size} bytes in 0 seconds") | |
else: | |
print(f"read {gb:.3f} GB in {duration:.3f} seconds ({gb/duration:.3f} GB/s)") |
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
#! /usr/bin/env python3 | |
import sys | |
import secrets | |
import time | |
assert len(sys.argv) == 3 | |
num_gb = int(sys.argv[1]) | |
assert sys.argv[1] == str(num_gb) | |
f = open(sys.argv[2], "wb") | |
start = time.perf_counter() | |
for _ in range(num_gb * 1_000): | |
f.write(secrets.token_bytes(1_000_000)) | |
end = time.perf_counter() | |
duration = end - start | |
print(f"wrote {num_gb} GB in {duration:.3f} seconds ({num_gb/duration:.3f} GB/s)") |
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
#! /usr/bin/env python3 | |
import sys | |
import time | |
assert len(sys.argv) == 2 | |
f = open(sys.argv[1], "rb") | |
total = 0 | |
start = time.perf_counter() | |
while True: | |
b = f.read(1 << 20) | |
total += len(b) | |
if len(b) == 0: | |
break | |
end = time.perf_counter() | |
gb = total / 1_000_000_000 | |
duration = end - start | |
if duration == 0: | |
print(f"read {total} bytes in 0 seconds") | |
else: | |
print(f"read {gb:.3f} GB in {duration:.3f} seconds ({gb/duration:.3f} GB/s)") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment