diff --git a/example/main.go b/example/main.go index 0fb9bfe28..de4360de8 100644 --- a/example/main.go +++ b/example/main.go @@ -1,18 +1,36 @@ package main import ( + "flag" "github.com/hajimehoshi/ebiten/example/blocks" "github.com/hajimehoshi/ebiten/ui" "github.com/hajimehoshi/ebiten/ui/glfw" + "log" + "os" "runtime" + "runtime/pprof" ) func init() { runtime.LockOSThread() } +var cpuProfile = flag.String("cpuprofile", "", "write cpu profile to file") + func main() { + flag.Parse() + if *cpuProfile != "" { + f, err := os.Create(*cpuProfile) + if err != nil { + log.Fatal(err) + } + pprof.StartCPUProfile(f) + defer pprof.StopCPUProfile() + } + u := new(glfw.UI) game := blocks.NewGame() - ui.Run(u, game, blocks.ScreenWidth, blocks.ScreenHeight, 2, "Ebiten Demo", 60) + if err := ui.Run(u, game, blocks.ScreenWidth, blocks.ScreenHeight, 2, "Ebiten Demo", 60); err != nil { + log.Fatal(err) + } } diff --git a/readme.md b/readme.md index e4dde0953..11e48681e 100644 --- a/readme.md +++ b/readme.md @@ -26,6 +26,15 @@ changed easily. :; go run main.go ``` +### How to benchmark the example + +``` +:; cd $GOHOME/src/github.com/hajimehoshi/ebiten/example +:; go build -o=example main.go +:; ./example -cpuprofile=cpu.out +:; go tool pprof ./example cpu.out +``` + ## License Copyright 2014 Hajime Hoshi