Skip to content

Instantly share code, notes, and snippets.

@johnjameswhitman
Last active November 9, 2023 14:37
Show Gist options
  • Save johnjameswhitman/0369fde2c259537d1d204ecdb9130b3b to your computer and use it in GitHub Desktop.
Save johnjameswhitman/0369fde2c259537d1d204ecdb9130b3b to your computer and use it in GitHub Desktop.
Machine Benchmarks
"""Endurance test the battery while watching video.
Videos to use (first two matter for OLED displays)...
- [white background video](https://www.youtube.com/watch?v=J3pF2jkQ4vc),
- [black background video](https://www.youtube.com/watch?v=XIMLoLxmTDw), and
- [nature video](https://www.youtube.com/watch?v=k-ZXEDMEaew)
"""
import logging
import time
import psutil
logging.basicConfig(
filename=f"endurance-{int(time.time())}.log",
format='%(asctime)s : %(levelname)s : %(message)s',
encoding="utf-8",
level=logging.DEBUG
)
def main(sleep_interval_seconds: int = 60):
t0 = time.monotonic()
while True:
battery_percent = f"{psutil.sensors_battery().percent:5.2f}%"
loop_time = f"{(time.monotonic() - t0):10.1f}s"
logging.info(
"Battery Percent: %s\t\tLoop Time: %s",
battery_percent,
loop_time,
)
time.sleep(sleep_interval_seconds)
if __name__ == "__main__":
main()
#!/usr/bin/env bash
set +e
SECONDS=0
now=$(date --iso-8601=seconds)
LOG="general_benchmark-${now}.log"
function log_time() {
echo "${SECONDS} : ${1}" | tee -a $LOG
}
log_time "free (before test)..."
log_time "$(free)"
log_time "========================================"
log_time "Creating tmpfs..."
sudo mkdir -p /mnt/ram_benchmark # memory
sudo mkdir -p /tmp/ssd_benchmark # disk
sudo mount -t tmpfs -o size=10G /mnt/ram_benchmark /mnt/ram_benchmark
log_time "tmpfs stats (df -h -t tmpfs)..."
log_time "$(df -h -t tmpfs)"
log_time "========================================"
log_time "Filling tmpfs..." | tee -a
log_time "$(sudo dd if=/dev/urandom of=/mnt/ram_benchmark/test bs=1M; sync)"
log_time "Finished filling tmpfs..."
log_time "========================================"
ram_time=$SECONDS
log_time "free (after filling tmpfs)..." | tee -a
log_time "$(free)"
log_time "========================================"
log_time "Copying random file to /tmp/ssd_benchmark/test"
sudo cp /mnt/ram_benchmark/test /tmp/ssd_benchmark
log_time "Finished copying..."
log_time "========================================"
ssd_time=$SECONDS
log_time "Comparing sha256 sums..." | tee -a
log_time "$(sha256sum /mnt/ram_benchmark/test /tmp/ssd_benchmark/test)"
log_time "Finished calculating sha256 sums"
log_time "========================================"
cpu_time=$SECONDS
log_time "Cleaning up..."
sudo umount /mnt/ram_benchmark
sudo rm -rf /mnt/ram_benchmark
sudo rm -rf /tmp/ssd_benchmark
log_time "========================================"
log_time "Duration of the test: ${SECONDS} seconds"
log_time "Stats..."
log_time "hostname,date,ram_time,ssd_time,cpu_time"
log_time "$(hostname),${now},${ram_time},${ssd_time},${cpu_time}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment