forked from codingberg/benchgraph
-
Notifications
You must be signed in to change notification settings - Fork 3
/
parse.go
35 lines (26 loc) · 930 Bytes
/
parse.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
package main
import (
"errors"
"regexp"
"strconv"
)
// Coder should use following naming convention for Benchmark functions
// Naming convention: Benchmark[Function_name]_[Function_argument](b *testing.B)
var re *regexp.Regexp = regexp.MustCompile(`Benchmark([a-zA-Z0-9/]+)_([_a-zA-Z0-9]+)-([0-9]+)$`)
// Storage for Func(Arg)=Result relations
type BenchArgSet map[string]float64
type BenchNameSet map[string]BenchArgSet
// parseNameArgThread parses function name, argument and number of threads from benchmark output.
func parseNameArgThread(line string) (name string, arg string, c int, err error) {
arr := re.FindStringSubmatch(line)
// we expect 4 columns
if len(arr) != 4 {
return "", "", 0, errors.New("Can't parse benchmark result")
}
name, arg = arr[1], arr[2]
c, err = strconv.Atoi(arr[3])
if err != nil {
return "", "", 0, errors.New("Can't parse benchmark result")
}
return name, arg, c, nil
}