-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
73 lines (60 loc) · 1.45 KB
/
main.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"fmt"
"io"
"os"
"github.com/alcortesm/git-diff-tree-benchmarks/gogit"
"github.com/alcortesm/git-diff-tree-benchmarks/gogitdev"
"github.com/alcortesm/git-diff-tree-benchmarks/libgit2"
"github.com/alcortesm/git-diff-tree-benchmarks/result"
)
type benchmarkFn func(string) (*result.Result, error)
type run struct {
name string
do benchmarkFn
}
var runs = []run{
{"libgit2", libgit2.Benchmark},
{"go-git", gogit.Benchmark},
{"go-git-dev", gogitdev.Benchmark},
}
func main() {
url, help, err := parseArgs()
if err != nil {
fmt.Fprintln(os.Stderr, err)
usage(os.Stderr)
os.Exit(1)
}
if help {
usage(os.Stdout)
os.Exit(0)
}
for _, r := range runs {
result, err := r.do(url)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
if err := result.Report(r.name + ".dat"); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
}
func parseArgs() (string, bool, error) {
if len(os.Args) != 2 {
return "", false, fmt.Errorf("bad number of arguments")
}
if os.Args[1] == "help" || os.Args[1] == "--help" {
return "", true, nil
}
return os.Args[1], false, nil
}
func usage(w io.Writer) {
fmt.Fprintln(w, "usage:")
fmt.Fprintf(w, "\t%s <git repository url> : to benchmark a git repository\n", os.Args[0])
fmt.Fprintln(w, "or")
fmt.Fprintf(w, "\t%s help : to get this help message\n", os.Args[0])
fmt.Fprintln(w, "or")
fmt.Fprintf(w, "\t%s --help : to get this help message\n", os.Args[0])
}