-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from mrf345/reader-writer-refactor
Reader writer refactor and improve performance (~3.6x faster)
- Loading branch information
Showing
43 changed files
with
1,687 additions
and
1,219 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,3 +24,4 @@ go.work.sum | |
# env file | ||
.env | ||
*.sla | ||
safelock-cli |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import os | ||
import json | ||
import random | ||
|
||
import matplotlib.pyplot as plt | ||
from matplotlib.colors import XKCD_COLORS as colors_map | ||
|
||
safelock_cmd = "safelock-cli" | ||
pwd = "123456789" | ||
rest = "60s" | ||
input_path = "test" | ||
output_name = "test" | ||
output_dir = "safelock_dump" | ||
runs = 3 | ||
figure_width = 14 | ||
figure_height = 2.5 | ||
bar_width = 0.6 | ||
measure = "Seconds" | ||
root = os.getcwd() | ||
|
||
def encrypt(): | ||
err = os.system( | ||
f"hyperfine --runs {runs} --prepare " | ||
f"'sleep {rest}' " | ||
f"'echo \"{pwd}\" | {safelock_cmd} encrypt {input_path} {output_name}.sla --quiet' " | ||
f"'echo \"{pwd}\" | {safelock_cmd} encrypt {input_path} {output_name}_sha256.sla --quiet --sha256' " | ||
f"'echo \"{pwd}\" | {safelock_cmd} encrypt {input_path} {output_name}_sha512.sla --quiet --sha512' " | ||
f"'gpgtar -e -o test.gpg -c --yes --batch --gpg-args \"--passphrase {pwd}\" Videos/' " | ||
f"--export-json {root}/encryption.json" | ||
) | ||
|
||
if err: | ||
exit(err) | ||
|
||
def decrypt(): | ||
err = os.system( | ||
f"hyperfine --runs {runs} --prepare " | ||
f"'rm -rf {output_dir} {output_name}_1_ && mkdir {output_dir} && sleep {rest}' " | ||
f"'echo \"{pwd}\" | {safelock_cmd} decrypt {output_name}.sla {output_dir} --quiet' " | ||
f"'echo \"{pwd}\" | {safelock_cmd} decrypt {output_name}_sha256.sla {output_dir} --quiet --sha256' " | ||
f"'echo \"{pwd}\" | {safelock_cmd} decrypt {output_name}_sha512.sla {output_dir} --quiet --sha512' " | ||
f"'gpgtar -d --yes --batch --gpg-args \"--passphrase {pwd}\" test.gpg' " | ||
f"--export-json {root}/decryption.json" | ||
) | ||
|
||
if err: | ||
exit(err) | ||
|
||
def get_label(i): | ||
label = i['command'] | ||
|
||
if 'gpg' in label: | ||
label = 'gpgtar' | ||
elif 'sha256' in label: | ||
label = 'safelock --sha256' | ||
elif 'sha512' in label: | ||
label = 'safelock --sha512' | ||
else: | ||
label = 'safelock' | ||
|
||
return f"{label}\n{i['median']:.3f}s" | ||
|
||
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] | ||
scores = [i['median'] for i in data] | ||
|
||
colors = [random.choice(list(colors_map.values())) for _ in scores] | ||
|
||
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) | ||
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] | ||
decryption = [i['median'] 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) | ||
fig.set_size_inches(w=figure_width, h=figure_height) | ||
fig.tight_layout() | ||
fig.savefig("decryption-time.webp", transparent=True, format="webp") |
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
{ | ||
"results": [ | ||
{ | ||
"command": "echo \"123456789\" | safelock-cli decrypt test.sla safelock_dump --quiet", | ||
"mean": 2.591056303126667, | ||
"stddev": 0.3072584303134709, | ||
"median": 2.4638408214600003, | ||
"user": 2.6658728066666666, | ||
"system": 1.96781978, | ||
"min": 2.36783672846, | ||
"max": 2.94149135946, | ||
"times": [ | ||
2.94149135946, | ||
2.36783672846, | ||
2.4638408214600003 | ||
], | ||
"exit_codes": [ | ||
0, | ||
0, | ||
0 | ||
] | ||
}, | ||
{ | ||
"command": "echo \"123456789\" | safelock-cli decrypt test_sha256.sla safelock_dump --quiet --sha256", | ||
"mean": 2.1992803144599997, | ||
"stddev": 0.4012681619295813, | ||
"median": 2.05163752946, | ||
"user": 2.160165473333333, | ||
"system": 1.6608864466666666, | ||
"min": 1.8927501014600001, | ||
"max": 2.65345331246, | ||
"times": [ | ||
2.65345331246, | ||
1.8927501014600001, | ||
2.05163752946 | ||
], | ||
"exit_codes": [ | ||
0, | ||
0, | ||
0 | ||
] | ||
}, | ||
{ | ||
"command": "echo \"123456789\" | safelock-cli decrypt test_sha512.sla safelock_dump --quiet --sha512", | ||
"mean": 2.1854930261266667, | ||
"stddev": 0.34595596536873846, | ||
"median": 2.12447426646, | ||
"user": 2.5949568066666666, | ||
"system": 1.4746104466666665, | ||
"min": 1.8741061304600002, | ||
"max": 2.55789868146, | ||
"times": [ | ||
2.55789868146, | ||
2.12447426646, | ||
1.8741061304600002 | ||
], | ||
"exit_codes": [ | ||
0, | ||
0, | ||
0 | ||
] | ||
}, | ||
{ | ||
"command": "gpgtar -d --yes --batch --gpg-args \"--passphrase 123456789\" test.gpg", | ||
"mean": 7.854353938126668, | ||
"stddev": 1.707887720081897, | ||
"median": 7.8766436114600005, | ||
"user": 0.22827714, | ||
"system": 1.6720551133333332, | ||
"min": 6.1354304734600005, | ||
"max": 9.55098772946, | ||
"times": [ | ||
9.55098772946, | ||
7.8766436114600005, | ||
6.1354304734600005 | ||
], | ||
"exit_codes": [ | ||
0, | ||
0, | ||
0 | ||
] | ||
} | ||
] | ||
} |
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
{ | ||
"results": [ | ||
{ | ||
"command": "echo \"123456789\" | safelock-cli encrypt test test.sla --quiet", | ||
"mean": 2.3078756149333333, | ||
"stddev": 0.019208610839248, | ||
"median": 2.3030128716, | ||
"user": 3.5797244999999998, | ||
"system": 1.2082247399999997, | ||
"min": 2.2915656946, | ||
"max": 2.3290482786, | ||
"times": [ | ||
2.3290482786, | ||
2.2915656946, | ||
2.3030128716 | ||
], | ||
"exit_codes": [ | ||
0, | ||
0, | ||
0 | ||
] | ||
}, | ||
{ | ||
"command": "echo \"123456789\" | safelock-cli encrypt test test_sha256.sla --quiet --sha256", | ||
"mean": 2.364359243266667, | ||
"stddev": 0.11326688774625213, | ||
"median": 2.3016267516, | ||
"user": 3.891836833333333, | ||
"system": 1.2837120733333334, | ||
"min": 2.2963380466000003, | ||
"max": 2.4951129316, | ||
"times": [ | ||
2.4951129316, | ||
2.2963380466000003, | ||
2.3016267516 | ||
], | ||
"exit_codes": [ | ||
0, | ||
0, | ||
0 | ||
] | ||
}, | ||
{ | ||
"command": "echo \"123456789\" | safelock-cli encrypt test test_sha512.sla --quiet --sha512", | ||
"mean": 2.4259253342666667, | ||
"stddev": 0.228772730074746, | ||
"median": 2.3097034366, | ||
"user": 4.034212833333334, | ||
"system": 1.2618734066666664, | ||
"min": 2.2785945276, | ||
"max": 2.6894780386, | ||
"times": [ | ||
2.6894780386, | ||
2.2785945276, | ||
2.3097034366 | ||
], | ||
"exit_codes": [ | ||
0, | ||
0, | ||
0 | ||
] | ||
}, | ||
{ | ||
"command": "gpgtar -e -o test.gpg -c --yes --batch --gpg-args \"--passphrase 123456789\" test/", | ||
"mean": 44.27242020093333, | ||
"stddev": 1.1158441010334361, | ||
"median": 44.070407816599996, | ||
"user": 34.355086166666666, | ||
"system": 10.122625073333332, | ||
"min": 43.2713822446, | ||
"max": 45.4754705416, | ||
"times": [ | ||
43.2713822446, | ||
45.4754705416, | ||
44.070407816599996 | ||
], | ||
"exit_codes": [ | ||
0, | ||
0, | ||
0 | ||
] | ||
} | ||
] | ||
} |
Oops, something went wrong.