Giter Site home page Giter Site logo

nockty / high-performance-go-workshop Goto Github PK

View Code? Open in Web Editor NEW

This project forked from davecheney/high-performance-go-workshop

0.0 0.0 0.0 52.26 MB

https://dave.cheney.net/high-performance-go-workshop/gophercon-2019.html

Go 68.87% Makefile 27.62% HTML 3.52%

high-performance-go-workshop's Introduction

Usage

You can view current version this presentation here

License and Materials

This presentation is licensed under the Creative Commons Attribution-ShareAlike 4.0 International licence.

You are encouraged to remix, transform, or build upon the material, providing you give appropriate credit and distribute your contributions under the same license.

Cheat sheet

Benchmarks

Basic command

go test -bench=. -cpu=1,2,4 -run=^$ ./examples/fib/

Comparison with benchstat

go test -c
mv fib.test fib.golden
go test -c
./fib.golden -test.bench=. -test.count=10 > old.txt
./fib.test -test.bench=. -test.count=10 > new.txt
benchstat old.txt new.txt

Look at assembly

go test -gcflags=-S
# disable inlining
go test -gcflags="-l -S"

Fixing compiler optimizations

var Result uint64

func BenchmarkPopcnt(b *testing.B) {
	var r uint64
	for i := 0; i < b.N; i++ {
		r = popcnt(uint64(i))
	}
	Result = r
}

Profiling

Profile benchmark

go test -run=XXX -bench=. -cpuprofile=c.p bytes
go tool pprof c.p

HTTP option (with flame graph mode)

go tool pprof -http=:8080 $FILENAME

Optimizations

Escape analysis & inlining

go build -gcflags=-m examples/esc/sum.go
go build -gcflags='-m -m' examples/esc/sum.go

go build -gcflags=-m examples/inl/max.go

Execution tracer

Get the trace

import "github.com/pkg/profile"

func main() {
	defer profile.Start(profile.TraceProfile, profile.ProfilePath(".")).Stop()
    // ...
}

Analyze the trace

go tool trace trace.out

high-performance-go-workshop's People

Contributors

davecheney avatar dgryski avatar dadabird avatar nockty avatar papulovskiy avatar flimzy avatar radeksimko avatar srlehn avatar cloudzhou avatar gotokatsuya avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.