"go/ast"
"go/parser"
"go/token"
+ "log"
+ "net/http"
+ _ "net/http/pprof"
"os"
"path"
"runtime"
"strings"
"time"
- "http"
- _ "http/pprof"
- "log"
)
var serve = flag.String("serve", "", "serve http on this address at end")
-func isGoFile(dir *os.FileInfo) bool {
- return dir.IsRegular() &&
- !strings.HasPrefix(dir.Name, ".") && // ignore .files
- path.Ext(dir.Name) == ".go"
+func isGoFile(dir os.FileInfo) bool {
+ return !dir.IsDir() &&
+ !strings.HasPrefix(dir.Name(), ".") && // ignore .files
+ path.Ext(dir.Name()) == ".go"
}
-func isPkgFile(dir *os.FileInfo) bool {
+func isPkgFile(dir os.FileInfo) bool {
return isGoFile(dir) &&
- !strings.HasSuffix(dir.Name, "_test.go") // ignore test files
+ !strings.HasSuffix(dir.Name(), "_test.go") // ignore test files
}
func pkgName(filename string) string {
_, pkgname := path.Split(dirpath)
// filter function to select the desired .go files
- filter := func(d *os.FileInfo) bool {
+ filter := func(d os.FileInfo) bool {
if isPkgFile(d) {
// Some directories contain main packages: Only accept
// files that belong to the expected package so that
// found" errors.
// Additionally, accept the special package name
// fakePkgName if we are looking at cmd documentation.
- name := pkgName(dirpath + "/" + d.Name)
+ name := pkgName(dirpath + "/" + d.Name())
return name == pkgname
}
return false
// get package AST
pkgs, err := parser.ParseDir(token.NewFileSet(), dirpath, filter, parser.ParseComments)
if err != nil {
- println("parse", dirpath, err.String())
+ println("parse", dirpath, err.Error())
panic("fail")
}
return pkgs
}
func main() {
- runtime.GOMAXPROCS(4)
- go func() {}()
- go func() {}()
- go func() {}()
st := &runtime.MemStats
packages = append(packages, packages...)
packages = append(packages, packages...)
flag.Parse()
var lastParsed []map[string]*ast.Package
- var t0 int64
+ var t0 time.Time
pkgroot := runtime.GOROOT() + "/src/pkg/"
for pass := 0; pass < 2; pass++ {
// Once the heap is grown to full size, reset counters.
// the average look much better than it actually is.
st.NumGC = 0
st.PauseTotalNs = 0
- t0 = time.Nanoseconds()
+ t0 = time.Now()
for i := 0; i < *n; i++ {
parsed := make([]map[string]*ast.Package, *p)
runtime.GC()
runtime.GC()
}
- t1 := time.Nanoseconds()
+ t1 := time.Now()
fmt.Printf("Alloc=%d/%d Heap=%d Mallocs=%d PauseTime=%.3f/%d = %.3f\n",
st.Alloc, st.TotalAlloc,
}
*/
// Standard gotest benchmark output, collected by build dashboard.
- gcstats("BenchmarkParser", *n, t1-t0)
+ gcstats("BenchmarkParser", *n, t1.Sub(t0))
if *serve != "" {
log.Fatal(http.ListenAndServe(*serve, nil))
}
}
-
var packages = []string{
"archive/tar",
- "asn1",
- "big",
+ "encoding/asn1",
+ "math/big",
"bufio",
"bytes",
- "cmath",
+ "math/cmplx",
"compress/flate",
"compress/gzip",
"compress/zlib",
"container/heap",
"container/list",
"container/ring",
- "container/vector",
"crypto/aes",
- "crypto/block",
"crypto/blowfish",
"crypto/hmac",
"crypto/md4",
"debug/macho",
"debug/elf",
"debug/gosym",
- "debug/proc",
- "ebnf",
+ "exp/ebnf",
"encoding/ascii85",
"encoding/base64",
"encoding/binary",
"encoding/git85",
"encoding/hex",
"encoding/pem",
- "exec",
- "exp/datafmt",
- "exp/draw",
- "exp/eval",
- "exp/iterable",
- "expvar",
+ "os/exec",
"flag",
"fmt",
"go/ast",
"go/printer",
"go/scanner",
"go/token",
- "gob",
+ "encoding/gob",
"hash",
"hash/adler32",
"hash/crc32",
"hash/crc64",
- "http",
+ "net/http",
"image",
"image/jpeg",
"image/png",
"io",
"io/ioutil",
- "json",
+ "encoding/json",
"log",
"math",
"mime",
"os/signal",
"patch",
"path",
- "rand",
+ "math/rand",
"reflect",
"regexp",
- "rpc",
+ "net/rpc",
"runtime",
- "scanner",
+ "text/scanner",
"sort",
- "smtp",
+ "net/smtp",
"strconv",
"strings",
"sync",
"syscall",
- "syslog",
- "tabwriter",
- "template",
+ "log/syslog",
+ "text/tabwriter",
+ "text/template",
"testing",
"testing/iotest",
"testing/quick",
"testing/script",
"time",
"unicode",
- "utf8",
- "utf16",
+ "unicode/utf8",
+ "unicode/utf16",
"websocket",
- "xml",
+ "encoding/xml",
}