goparsify/json/profile/json.go

56 lines
915 B
Go
Raw Normal View History

2017-08-06 11:15:07 +02:00
package main
import (
"flag"
"log"
"os"
"runtime"
"runtime/pprof"
"github.com/vektah/goparsify/json"
)
var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
var memprofile = flag.String("memprofile", "", "write memory profile to this file")
func main() {
flag.Parse()
if *cpuprofile != "" {
f, err := os.Create(*cpuprofile)
if err != nil {
log.Fatal(err)
}
pprof.StartCPUProfile(f)
defer func() {
pprof.StopCPUProfile()
err := f.Close()
if err != nil {
panic(err)
}
}()
}
2017-08-06 15:32:10 +02:00
max := 1000000
2017-08-06 11:15:07 +02:00
if *memprofile != "" {
runtime.MemProfileRate = 1
2017-08-07 14:38:34 +02:00
max = 100000
defer func() {
f, err := os.Create(*memprofile)
if err != nil {
log.Fatal(err)
}
pprof.WriteHeapProfile(f)
f.Close()
}()
2017-08-06 11:15:07 +02:00
}
2017-08-06 15:32:10 +02:00
for i := 0; i < max; i++ {
2017-08-06 11:15:07 +02:00
_, err := json.Unmarshal(`{"true":true, "false":false, "null": null}`)
if err != nil {
panic(err)
}
}
}