Golang Closure Benchmark


Get the code:

$ go get github.com/sunfmin/benchmark_go_closures
$ cd $GOPATH/src/github.com/sunfmin/benchmark_go_closures/

Now run the benchmark:

$ go test -test.bench=.*
BenchmarkAnonymousFunction-8          	1000000000	         2.42 ns/op
BenchmarkReusingAnonymousFunction-8   	1000000000	         2.40 ns/op
BenchmarkClosure-8                    	1000000000	         2.48 ns/op
BenchmarkReusingClosure-8             	1000000000	         2.14 ns/op
BenchmarkNormalFunction-8             	2000000000	         0.47 ns/op
PASS
ok  	github.com/sunfmin/benchmark_go_closures	11.417s
Posted on Mon May 22 03:59:56 EDT 2017 by Subhash Chandran
golang