Last active
May 26, 2017 18:46
-
-
Save hajimehoshi/5ed631114901acc7a7ce019449c6bf36 to your computer and use it in GitHub Desktop.
GopherJS's defer performance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test | |
import ( | |
"testing" | |
) | |
var i = 0 | |
func begin() { | |
i++ | |
} | |
func end() { | |
i-- | |
} | |
func fooNormal() { | |
begin() | |
end() | |
} | |
func fooDefer() { | |
begin() | |
defer end() | |
} | |
func BenchmarkNormal(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
fooNormal() | |
} | |
} | |
func BenchmarkDefer(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
fooDefer() | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ gopherjs version | |
GopherJS 1.8-1 | |
$ gopherjs test --bench="." github.com/hajimehoshi/test | |
gopherjs: Source maps disabled. Install source-map-support module for nice stack traces. See https://github.com/gopherjs/gopherjs#gopherjs-run-gopherjs-test. | |
BenchmarkNormal 300000000 5.26 ns/op | |
BenchmarkDefer 10000000 137 ns/op | |
PASS | |
fatal error: all goroutines are asleep - deadlock! | |
FAIL github.com/hajimehoshi/test 4.047s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment