Command | Min (s) | Max (s) | Average (s) |
---|---|---|---|
snap run | 2.06 | 2.48 | 2.17 |
~/bin/syft run | 2.04 | 2.47 | 2.19 |
Created
February 14, 2025 10:33
-
-
Save popey/f6c1d7a96c5e6485921e8b1b96896758 to your computer and use it in GitHub Desktop.
A script to compare the runtime of a snap vs non-snap binary
This file contains hidden or 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 subprocess | |
import time | |
from statistics import mean | |
import json | |
def run_command(command, iterations=10): | |
durations = [] | |
for i in range(iterations): | |
start_time = time.time() | |
result = subprocess.run(command.split(), capture_output=True) | |
if result.returncode != 0: | |
print(f"Error running command: {result.stderr.decode()}") | |
continue | |
duration = time.time() - start_time | |
durations.append(duration) | |
print(f"Iteration {i+1}: {duration:.2f}s") | |
return durations | |
# Commands to test | |
snap_command = "snap run syft -q ubuntu:latest -o syft-json=sbom_ubuntu_latest.json" | |
local_command = "/home/alan/bin/syft -q ubuntu:latest -o syft-json=sbom_ubuntu_latest.json" | |
print("Testing snap command...") | |
snap_times = run_command(snap_command) | |
print("\nTesting local command...") | |
local_times = run_command(local_command) | |
# Generate markdown table | |
print("\n| Command | Min (s) | Max (s) | Average (s) |") | |
print("|---------|---------|---------|-------------|") | |
print(f"| snap run | {min(snap_times):.2f} | {max(snap_times):.2f} | {mean(snap_times):.2f} |") | |
print(f"| ~/bin/syft run | {min(local_times):.2f} | {max(local_times):.2f} | {mean(local_times):.2f} |") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment