Skip to content

Commit

Permalink
Merge pull request #11 from mrf345/testing
Browse files Browse the repository at this point in the history
Fix plot colors and links
  • Loading branch information
mrf345 authored Sep 3, 2024
2 parents 1087c43 + 6960ec7 commit fcc9ef9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,12 @@ With the default settings it should be about **19.1** times faster than `gpgtar`
> You can reproduce the results by running [bench_and_plot.py](benchmark/bench_and_plot.py) (based on [matplotlib](https://github.com/matplotlib/matplotlib) and [hyperfine](https://github.com/sharkdp/hyperfine))
<p align="center">
<img src="benchmark/encryption-time.webp" align="center" alt="encryption time" />
<img src="benchmark/decryption-time.webp" align="center" alt="encryption time" />
<a href="https://raw.githubusercontent.com/mrf345/safelock-cli/master/benchmark/encryption-time.webp" target="_blank">
<img src="benchmark/encryption-time.webp" align="center" alt="encryption time" />
</a>
<a href="https://raw.githubusercontent.com/mrf345/safelock-cli/master/benchmark/decryption-time.webp" target="_blank">
<img src="benchmark/decryption-time.webp" align="center" alt="encryption time" />
</a>
</p>

And you could gain a slight file size reduction
Expand Down
26 changes: 15 additions & 11 deletions benchmark/bench_and_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import random

import matplotlib.pyplot as plt
from matplotlib.colors import XKCD_COLORS as colors_map
from matplotlib.colors import XKCD_COLORS as plot_colors

safelock_cmd = "safelock-cli"
pwd = "123456789"
Expand Down Expand Up @@ -46,7 +46,7 @@ def decrypt():
if err:
exit(err)

def get_label(i):
def get_label(i, clean=False):
label = i['command']

if 'gpg' in label:
Expand All @@ -58,39 +58,43 @@ def get_label(i):
else:
label = 'safelock'

if clean:
return label

return f"{label}\n{i['median']:.3f}s"

os.chdir(os.path.expanduser("~"))
encrypt()
decrypt()
# os.chdir(os.path.expanduser("~"))
# encrypt()
# decrypt()
os.chdir(root)

with open("encryption.json") as f:
data = sorted(json.load(f)['results'], key=lambda i: i['median'])
commands = [get_label(i) for i in data]
labels = [get_label(i) for i in data]
scores = [i['median'] for i in data]

colors = [random.choice(list(colors_map.values())) for _ in scores]
colors_map = {get_label(i, 1): random.choice(list(plot_colors.values())) for i in data}
colors = [colors_map[get_label(i, 1)] for i in data]

plt.margins(3.5)

fig, ax = plt.subplots()
ax.set_title('Encryption Time')
ax.set_xlabel(measure)
ax.barh(commands, scores, bar_width, color=colors)
ax.barh(labels, scores, bar_width, color=colors)
fig.set_size_inches(w=figure_width, h=figure_height)
fig.tight_layout()
fig.savefig("encryption-time.webp", transparent=True, format="webp")

with open("decryption.json") as f:
data = sorted(json.load(f)['results'], key=lambda i: i['median'])
commands = [get_label(i) for i in data]
labels = [get_label(i) for i in data]
decryption = [i['median'] for i in data]
colors = [colors_map[get_label(i, 1)] for i in data]

fig, ax = plt.subplots()
ax.set_title('Decryption Time')
ax.set_xlabel(measure)
ax.barh(commands, decryption, bar_width, color=colors)
ax.barh(labels, decryption, bar_width, color=colors)
fig.set_size_inches(w=figure_width, h=figure_height)
fig.tight_layout()
fig.savefig("decryption-time.webp", transparent=True, format="webp")
Binary file modified benchmark/decryption-time.webp
Binary file not shown.
Binary file modified benchmark/encryption-time.webp
Binary file not shown.

0 comments on commit fcc9ef9

Please sign in to comment.