func BenchmarkRendering(b *testing.B) { if sdl.Init(sdl.INIT_EVERYTHING) != 0 { log.Fatal(sdl.GetError()) } screen := smslib.NewSDL2xScreen(false) displayLoop := smslib.NewSDLLoop(screen) go displayLoop.Run() sms := smslib.NewSMS(displayLoop) sms.LoadROM("../roms/blockhead.sms") numOfGeneratedFrames := 100 generatedFrames := make([]smslib.DisplayData, numOfGeneratedFrames) for i := 0; i < numOfGeneratedFrames; i++ { generatedFrames = append(generatedFrames, *sms.RenderFrame()) } b.ResetTimer() for i := 0; i < b.N; i++ { for _, frame := range generatedFrames { displayLoop.Display() <- &frame } } }
func main() { verbose := flag.Bool("verbose", false, "verbose mode") debug := flag.Bool("debug", false, "debug mode") fullScreen := flag.Bool("fullscreen", false, "go fullscreen") cpuProfile := flag.String("cpuprofile", "", "write cpu profile to file") help := flag.Bool("help", false, "Show usage") flag.Usage = usage flag.Parse() if *help { usage() return } if *cpuProfile != "" { f, err := os.Create(*cpuProfile) if err != nil { log.Fatal(err) } pprof.StartCPUProfile(f) defer pprof.StopCPUProfile() } application.Verbose = *verbose application.Debug = *debug if sdl.Init(sdl.INIT_EVERYTHING) != 0 { log.Fatal(sdl.GetError()) } screen := sms.NewSDL2xScreen(*fullScreen) sdlLoop := sms.NewSDLLoop(screen) emulatorLoop := newEmulatorLoop(sdlLoop) if emulatorLoop == nil { usage() return } cpuProfiling := *cpuProfile != "" commandLoop := newCommandLoop(emulatorLoop, sdlLoop, cpuProfiling) inputLoop := sms.NewInputLoop(emulatorLoop.sms) application.Register("Emulator loop", emulatorLoop) application.Register("Command loop", commandLoop) application.Register("SDL render loop", sdlLoop) application.Register("SDL input loop", inputLoop) exitCh := make(chan bool) application.Run(exitCh) <-exitCh sdl.Quit() }
func BenchmarkCPU(b *testing.B) { if sdl.Init(sdl.INIT_EVERYTHING) != 0 { log.Fatal(sdl.GetError()) } screen := smslib.NewSDL2xScreen(false) displayLoop := smslib.NewSDLLoop(screen) go displayLoop.Run() sms := smslib.NewSMS(displayLoop) sms.LoadROM("../roms/blockhead.sms") b.ResetTimer() for i := 0; i < b.N; i++ { sms.RenderFrame() } }