summaryrefslogtreecommitdiff
path: root/json/profile
diff options
context:
space:
mode:
authorAdam Scarr <adam@vektah.net>2017-08-06 19:15:07 +1000
committerAdam Scarr <adam@vektah.net>2017-08-06 19:15:07 +1000
commit9d7779e8ca5404f26abbd8cce0314d9cee967bba (patch)
tree5d0ae8546ff5c657e1edd0559093831a9e0c839b /json/profile
parent2c0c5b628fd0b8e7499574d379b4138630f886d7 (diff)
Add a json parser
Diffstat (limited to 'json/profile')
-rw-r--r--json/profile/cpuprofile.bat3
-rw-r--r--json/profile/json.go55
-rw-r--r--json/profile/memprofile.bat3
3 files changed, 61 insertions, 0 deletions
diff --git a/json/profile/cpuprofile.bat b/json/profile/cpuprofile.bat
new file mode 100644
index 0000000..2899eb3
--- /dev/null
+++ b/json/profile/cpuprofile.bat
@@ -0,0 +1,3 @@
+go build
+profile.exe -cpuprofile cpu.out
+go tool pprof --inuse_objects profile.exe cpu.out
diff --git a/json/profile/json.go b/json/profile/json.go
new file mode 100644
index 0000000..b94848b
--- /dev/null
+++ b/json/profile/json.go
@@ -0,0 +1,55 @@
+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)
+ }
+ }()
+ }
+ if *memprofile != "" {
+ runtime.MemProfileRate = 1
+ }
+
+ for i := 0; i < 10000; i++ {
+ _, err := json.Unmarshal(`{"true":true, "false":false, "null": null}`)
+ if err != nil {
+ panic(err)
+ }
+ }
+
+ if *memprofile != "" {
+ f, err := os.Create(*memprofile)
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ pprof.WriteHeapProfile(f)
+ f.Close()
+ return
+ }
+}
diff --git a/json/profile/memprofile.bat b/json/profile/memprofile.bat
new file mode 100644
index 0000000..a9c935e
--- /dev/null
+++ b/json/profile/memprofile.bat
@@ -0,0 +1,3 @@
+go build
+profile.exe -memprofile mem.out
+go tool pprof --inuse_objects profile.exe mem.out