OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [go.test/] [test/] [bench/] [garbage/] [parser.go] - Blame information for rev 700

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 700 jeremybenn
// Copyright 2010 The Go Authors.  All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
4
 
5
// Garbage collection benchmark: parse Go packages repeatedly.
6
 
7
package main
8
 
9
import (
10
        "flag"
11
        "fmt"
12
        "go/ast"
13
        "go/parser"
14
        "go/token"
15
        "log"
16
        "net/http"
17
        _ "net/http/pprof"
18
        "os"
19
        "path"
20
        "runtime"
21
        "strings"
22
        "time"
23
)
24
 
25
var serve = flag.String("serve", "", "serve http on this address at end")
26
 
27
func isGoFile(dir os.FileInfo) bool {
28
        return !dir.IsDir() &&
29
                !strings.HasPrefix(dir.Name(), ".") && // ignore .files
30
                path.Ext(dir.Name()) == ".go"
31
}
32
 
33
func isPkgFile(dir os.FileInfo) bool {
34
        return isGoFile(dir) &&
35
                !strings.HasSuffix(dir.Name(), "_test.go") // ignore test files
36
}
37
 
38
func pkgName(filename string) string {
39
        file, err := parser.ParseFile(token.NewFileSet(), filename, nil, parser.PackageClauseOnly)
40
        if err != nil || file == nil {
41
                return ""
42
        }
43
        return file.Name.Name
44
}
45
 
46
func parseDir(dirpath string) map[string]*ast.Package {
47
        // the package name is the directory name within its parent
48
        // (use dirname instead of path because dirname is clean; i.e. has no trailing '/')
49
        _, pkgname := path.Split(dirpath)
50
 
51
        // filter function to select the desired .go files
52
        filter := func(d os.FileInfo) bool {
53
                if isPkgFile(d) {
54
                        // Some directories contain main packages: Only accept
55
                        // files that belong to the expected package so that
56
                        // parser.ParsePackage doesn't return "multiple packages
57
                        // found" errors.
58
                        // Additionally, accept the special package name
59
                        // fakePkgName if we are looking at cmd documentation.
60
                        name := pkgName(dirpath + "/" + d.Name())
61
                        return name == pkgname
62
                }
63
                return false
64
        }
65
 
66
        // get package AST
67
        pkgs, err := parser.ParseDir(token.NewFileSet(), dirpath, filter, parser.ParseComments)
68
        if err != nil {
69
                println("parse", dirpath, err.Error())
70
                panic("fail")
71
        }
72
        return pkgs
73
}
74
 
75
func main() {
76
        st := &runtime.MemStats
77
        packages = append(packages, packages...)
78
        packages = append(packages, packages...)
79
        n := flag.Int("n", 4, "iterations")
80
        p := flag.Int("p", len(packages), "# of packages to keep in memory")
81
        flag.BoolVar(&st.DebugGC, "d", st.DebugGC, "print GC debugging info (pause times)")
82
        flag.Parse()
83
 
84
        var lastParsed []map[string]*ast.Package
85
        var t0 time.Time
86
        pkgroot := runtime.GOROOT() + "/src/pkg/"
87
        for pass := 0; pass < 2; pass++ {
88
                // Once the heap is grown to full size, reset counters.
89
                // This hides the start-up pauses, which are much smaller
90
                // than the normal pauses and would otherwise make
91
                // the average look much better than it actually is.
92
                st.NumGC = 0
93
                st.PauseTotalNs = 0
94
                t0 = time.Now()
95
 
96
                for i := 0; i < *n; i++ {
97
                        parsed := make([]map[string]*ast.Package, *p)
98
                        for j := range parsed {
99
                                parsed[j] = parseDir(pkgroot + packages[j%len(packages)])
100
                        }
101
                        if i+1 == *n && *serve != "" {
102
                                lastParsed = parsed
103
                        }
104
                }
105
                runtime.GC()
106
                runtime.GC()
107
        }
108
        t1 := time.Now()
109
 
110
        fmt.Printf("Alloc=%d/%d Heap=%d Mallocs=%d PauseTime=%.3f/%d = %.3f\n",
111
                st.Alloc, st.TotalAlloc,
112
                st.Sys,
113
                st.Mallocs, float64(st.PauseTotalNs)/1e9,
114
                st.NumGC, float64(st.PauseTotalNs)/1e9/float64(st.NumGC))
115
 
116
        /*
117
                fmt.Printf("%10s %10s %10s\n", "size", "#alloc", "#free")
118
                for _, s := range st.BySize {
119
                        fmt.Printf("%10d %10d %10d\n", s.Size, s.Mallocs, s.Frees)
120
                }
121
        */
122
        // Standard gotest benchmark output, collected by build dashboard.
123
        gcstats("BenchmarkParser", *n, t1.Sub(t0))
124
 
125
        if *serve != "" {
126
                log.Fatal(http.ListenAndServe(*serve, nil))
127
                println(lastParsed)
128
        }
129
}
130
 
131
var packages = []string{
132
        "archive/tar",
133
        "encoding/asn1",
134
        "math/big",
135
        "bufio",
136
        "bytes",
137
        "math/cmplx",
138
        "compress/flate",
139
        "compress/gzip",
140
        "compress/zlib",
141
        "container/heap",
142
        "container/list",
143
        "container/ring",
144
        "crypto/aes",
145
        "crypto/blowfish",
146
        "crypto/hmac",
147
        "crypto/md4",
148
        "crypto/md5",
149
        "crypto/rand",
150
        "crypto/rc4",
151
        "crypto/rsa",
152
        "crypto/sha1",
153
        "crypto/sha256",
154
        "crypto/sha512",
155
        "crypto/subtle",
156
        "crypto/tls",
157
        "crypto/x509",
158
        "crypto/xtea",
159
        "debug/dwarf",
160
        "debug/macho",
161
        "debug/elf",
162
        "debug/gosym",
163
        "exp/ebnf",
164
        "encoding/ascii85",
165
        "encoding/base64",
166
        "encoding/binary",
167
        "encoding/git85",
168
        "encoding/hex",
169
        "encoding/pem",
170
        "os/exec",
171
        "flag",
172
        "fmt",
173
        "go/ast",
174
        "go/doc",
175
        "go/parser",
176
        "go/printer",
177
        "go/scanner",
178
        "go/token",
179
        "encoding/gob",
180
        "hash",
181
        "hash/adler32",
182
        "hash/crc32",
183
        "hash/crc64",
184
        "net/http",
185
        "image",
186
        "image/jpeg",
187
        "image/png",
188
        "io",
189
        "io/ioutil",
190
        "encoding/json",
191
        "log",
192
        "math",
193
        "mime",
194
        "net",
195
        "os",
196
        "os/signal",
197
        "patch",
198
        "path",
199
        "math/rand",
200
        "reflect",
201
        "regexp",
202
        "net/rpc",
203
        "runtime",
204
        "text/scanner",
205
        "sort",
206
        "net/smtp",
207
        "strconv",
208
        "strings",
209
        "sync",
210
        "syscall",
211
        "log/syslog",
212
        "text/tabwriter",
213
        "text/template",
214
        "testing",
215
        "testing/iotest",
216
        "testing/quick",
217
        "testing/script",
218
        "time",
219
        "unicode",
220
        "unicode/utf8",
221
        "unicode/utf16",
222
        "websocket",
223
        "encoding/xml",
224
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.