forked from jedib0t/go-pretty
-
Notifications
You must be signed in to change notification settings - Fork 0
/
profile.go
57 lines (50 loc) · 1.21 KB
/
profile.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
package main
import (
"fmt"
"os"
"strconv"
"github.com/SilverChard/go-pretty/v6/table"
"github.com/pkg/profile"
)
var (
profilers = []func(*profile.Profile){
profile.CPUProfile,
profile.MemProfileRate(512),
}
tableCaption = "Profiling a Simple Table."
tableRowFooter = table.Row{"", "", "Total", 10000}
tableRowHeader = table.Row{"#", "First Name", "Last Name", "Salary"}
tableRows = []table.Row{
{1, "Arya", "Stark", 3000},
{20, "Jon", "Snow", 2000, "You know nothing, Jon Snow!"},
{300, "Tyrion", "Lannister", 5000},
}
)
func profileRender(profiler func(profile2 *profile.Profile), n int) {
defer profile.Start(profiler, profile.ProfilePath(".")).Stop()
for i := 0; i < n; i++ {
tw := table.NewWriter()
tw.AppendHeader(tableRowHeader)
tw.AppendRows(tableRows)
tw.AppendFooter(tableRowFooter)
tw.SetCaption(tableCaption)
tw.Render()
tw.RenderCSV()
tw.RenderHTML()
tw.RenderMarkdown()
}
}
func main() {
numRenders := 100000
if len(os.Args) > 1 {
var err error
numRenders, err = strconv.Atoi(os.Args[2])
if err != nil {
fmt.Printf("Invalid Argument: '%s'\n", os.Args[2])
os.Exit(1)
}
}
for _, profiler := range profilers {
profileRender(profiler, numRenders)
}
}