Skip to content

Commit

Permalink
Add benchmarking to encrypt, decrypt, and walk
Browse files Browse the repository at this point in the history
Add file generation with sizes of 2mb, 4mb, 8mb, 16mb, 32mb, 64mb,
128mb, 256mb, 512mb, 1024mb, 2048mb. These files are created using dd
from /dev/random. The files get copied into a container and then
benchmarking is ran on the encryptfile.EncryptFile.Do,
decryptfile.DecryptFile.Do, and walk.Walk for both encrypt and decrypt.
It uses these files for benchmarking.
  • Loading branch information
prairir committed Nov 29, 2021
1 parent 9aaf2ad commit 3102bfc
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,26 @@ docker:
COPY +build/imacry imacry

SAVE IMAGE imacry-run:latest

# make the benchmarking files
make-benchmark:
FROM ubuntu:21.04

# copy shell script
COPY scripts/test_filebenchmarks.sh .

# make it executable and then run it
RUN chmod +x test_filebenchmarks.sh && \
./test_filebenchmarks.sh

SAVE ARTIFACT /root/file*

# benchmarking docker container
benchmark:
FROM +build

COPY +make-benchmark/file* /root/

CMD ["go", "test", "-bench=.", "./..."]

SAVE IMAGE imacry-benchmark:latest
37 changes: 37 additions & 0 deletions pkg/decryptfile/decryptfile_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package decryptfile_test

import (
"testing"

"github.com/prairir/imacry/pkg/config"
"github.com/prairir/imacry/pkg/decryptfile"
)

var dec = decryptfile.DecryptFile{}

func BenchmarkDecryptFile(b *testing.B) {
config.Config.Password = "123456789012345678901234"
tests := []struct {
name string
filePath string
}{
{"2MB", "/root/file00"},
{"4MB", "/root/file01"},
{"8MB", "/root/file02"},
{"16MB", "/root/file03"},
{"32MB", "/root/file04"},
{"64MB", "/root/file05"},
{"128MB", "/root/file06"},
{"256MB", "/root/file07"},
{"512MB", "/root/file08"},
{"1024MB", "/root/file09"},
{"2056MB", "/root/file10"},
}
for _, test := range tests {
b.Run(test.name, func(b *testing.B) {
for i := 0; i < b.N; i++ {
dec.Do(test.filePath)
}
})
}
}
37 changes: 37 additions & 0 deletions pkg/encryptfile/encryptfile_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package encryptfile_test

import (
"testing"

"github.com/prairir/imacry/pkg/config"
"github.com/prairir/imacry/pkg/encryptfile"
)

var enc = encryptfile.EncryptFile{}

func BenchmarkEncryptFile(b *testing.B) {
config.Config.Password = "123456789012345678901234"
tests := []struct {
name string
filePath string
}{
{"2MB", "/root/file00"},
{"4MB", "/root/file01"},
{"8MB", "/root/file02"},
{"16MB", "/root/file03"},
{"32MB", "/root/file04"},
{"64MB", "/root/file05"},
{"128MB", "/root/file06"},
{"256MB", "/root/file07"},
{"512MB", "/root/file08"},
{"1024MB", "/root/file09"},
{"2056MB", "/root/file10"},
}
for _, test := range tests {
b.Run(test.name, func(b *testing.B) {
for i := 0; i < b.N; i++ {
enc.Do(test.filePath)
}
})
}
}
29 changes: 29 additions & 0 deletions pkg/walk/walk_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package walk_test

import (
"testing"

"github.com/prairir/imacry/pkg/config"
"github.com/prairir/imacry/pkg/decryptfile"
"github.com/prairir/imacry/pkg/encryptfile"
"github.com/prairir/imacry/pkg/walk"
)

func BenchmarkWalk(b *testing.B) {
config.Config.Password = "123456789012345678901234"

tests := []struct {
name string
fun walk.FileAction
}{
{"encrypt", encryptfile.EncryptFile{}},
{"decrypt", decryptfile.DecryptFile{}},
}
for _, test := range tests {
b.Run(test.name, func(b *testing.B) {
for i := 0; i < b.N; i++ {
walk.Walk("/root/", test.fun)
}
})
}
}
31 changes: 31 additions & 0 deletions scripts/test_filebenchmarks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

set -euxo

# benchmarking script
# creates a large number of files

# filename is of
# file size is (bs * count)

dd if=/dev/random of=~/file00 bs=1M count=2

dd if=/dev/random of=~/file01 bs=1M count=4

dd if=/dev/random of=~/file02 bs=1M count=8

dd if=/dev/random of=~/file03 bs=1M count=16

dd if=/dev/random of=~/file04 bs=1M count=32

dd if=/dev/random of=~/file05 bs=1M count=64

dd if=/dev/random of=~/file06 bs=1M count=128

dd if=/dev/random of=~/file07 bs=1M count=256

dd if=/dev/random of=~/file08 bs=1M count=512

dd if=/dev/random of=~/file09 bs=1M count=1024

dd if=/dev/random of=~/file10 bs=1M count=2048

0 comments on commit 3102bfc

Please sign in to comment.