-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutil.go
43 lines (34 loc) · 761 Bytes
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package benchmark
import (
"os"
"math/rand"
"path"
"testing"
"time"
"log"
)
func SetupDir(dirname string, t *testing.T) string {
dir, err := os.Getwd()
if err != nil {
t.Fatalf("failed to open dir: %v", err)
}
datadir := path.Join(dir, "..", "data", dirname)
if err := os.RemoveAll(datadir); err != nil {
t.Fatalf("failed to clean dir: %v", err)
}
if err := os.MkdirAll(datadir, 0700); err != nil {
t.Fatalf("failed to create dir: %v", err)
}
return datadir
}
func TrackTime(start time.Time, name string) {
elapsed := time.Since(start)
log.Printf("%s took %s", name, elapsed)
}
func GenerateKV(r *rand.Rand) ([]byte, []byte) {
key := make([]byte, 32)
r.Read(key)
value := make([]byte, 300)
r.Read(value)
return key, value
}