summaryrefslogtreecommitdiff
path: root/integration_tests/performance_test.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2015-11-14 16:40:05 +0100
committerJakob Unterwurzacher2015-11-14 16:49:59 +0100
commitf9c21e91aab4799425b25f5fb876c9d95865d9dc (patch)
tree7c76f56355a33aa9c0ddceea4fa0e89ad7126c16 /integration_tests/performance_test.go
parent2e3388800d028fee3e2b9cf6cfca2c878b7e6327 (diff)
tests: Add file create benchmarks for different sizes
Example output on my machine: ~/src/github.com/rfjakob/gocryptfs$ ./benchmark.bash gocryptfs v0.3.1-25-g2e33888-dirty; on-disk format 2 PASS BenchmarkStreamWrite-2 100 12189867 ns/op 86.02 MB/s BenchmarkStreamRead-2 200 9113262 ns/op 115.06 MB/s BenchmarkCreate0B-2 10000 100249 ns/op BenchmarkCreate1B-2 10000 177680 ns/op 0.01 MB/s BenchmarkCreate100B-2 3000 431586 ns/op 0.23 MB/s BenchmarkCreate4kB-2 3000 455204 ns/op 9.00 MB/s BenchmarkCreate10kB-2 3000 594044 ns/op 17.24 MB/s ok github.com/rfjakob/gocryptfs/integration_tests 15.176s
Diffstat (limited to 'integration_tests/performance_test.go')
-rw-r--r--integration_tests/performance_test.go52
1 files changed, 40 insertions, 12 deletions
diff --git a/integration_tests/performance_test.go b/integration_tests/performance_test.go
index 7667243..e46cb91 100644
--- a/integration_tests/performance_test.go
+++ b/integration_tests/performance_test.go
@@ -34,7 +34,10 @@ func BenchmarkStreamRead(t *testing.B) {
t.SetBytes(int64(len(buf)))
fn := plainDir + "BenchmarkWrite"
- fi, _ := os.Stat(fn)
+ fi, err := os.Stat(fn)
+ if err != nil {
+ t.Fatal(err)
+ }
mb := int(fi.Size() / 1024 / 1024)
if t.N > mb {
@@ -56,7 +59,7 @@ func BenchmarkStreamRead(t *testing.B) {
//fmt.Printf("done\n")
}
- file, err := os.Open(plainDir + "BenchmarkWrite")
+ file, err := os.Open(fn)
if err != nil {
t.FailNow()
}
@@ -75,25 +78,50 @@ func BenchmarkStreamRead(t *testing.B) {
file.Close()
}
-func BenchmarkCreate10B(t *testing.B) {
- dir := plainDir + "BenchmarkCreate10B"
- err := os.RemoveAll(dir)
+// createFiles - create "count" files of size "size" bytes each
+func createFiles(t *testing.B, count int, size int) {
+ dir := fmt.Sprintf("%s/createFiles_%d_%d", plainDir, count, size)
+ err := os.Mkdir(dir, 0777)
if err != nil {
t.Fatal(err)
}
- err = os.Mkdir(dir, 0777)
- if err != nil {
- t.Fatal(err)
- }
- buf := []byte("1234567890")
+ buf := make([]byte, size)
t.SetBytes(int64(len(buf)))
t.ResetTimer()
var i int
- for i = 0; i < t.N; i++ {
+ for i = 0; i < count; i++ {
file := fmt.Sprintf("%s/%d", dir, i)
- err = ioutil.WriteFile(file, buf, 0666)
+ if size > 0 {
+ err = ioutil.WriteFile(file, buf, 0666)
+ } else {
+ var fh *os.File
+ fh, err = os.Create(file)
+ fh.Close()
+ }
if err != nil {
t.Fatal(err)
}
}
+ t.StopTimer()
+ os.RemoveAll(dir)
+}
+
+func BenchmarkCreate0B(t *testing.B) {
+ createFiles(t, t.N, 0)
+}
+
+func BenchmarkCreate1B(t *testing.B) {
+ createFiles(t, t.N, 1)
+}
+
+func BenchmarkCreate100B(t *testing.B) {
+ createFiles(t, t.N, 100)
+}
+
+func BenchmarkCreate4kB(t *testing.B) {
+ createFiles(t, t.N, 4*1024)
+}
+
+func BenchmarkCreate10kB(t *testing.B) {
+ createFiles(t, t.N, 10*1024)
}