Last active
December 12, 2015 05:38
-
-
Save shanna/4723245 to your computer and use it in GitHub Desktop.
Evil or awesome use of tags in golang for debugging?
This file contains 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
#!/bin/sh | |
go test -test.bench . 2> /dev/null | |
go test -tags debug -test.bench . 2> /dev/null |
This file contains 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
PASS | |
BenchmarkDebug 100000000 13.3 ns/op | |
ok _/home/shane/projects/log 1.356s | |
PASS | |
BenchmarkDebug 2000000 839 ns/op | |
ok _/home/shane/projects/log 2.541s |
This file contains 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
// +build debug | |
package log | |
import ( | |
"fmt" | |
"os" | |
) | |
// Complicated as you like, include line numbers and such. | |
func Debugf(format string, v ...interface{}) { | |
fmt.Fprintf(os.Stderr, format, v...) | |
} |
This file contains 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
// +build !debug | |
package log | |
// Just a stub. | |
func Debugf(format string, v ...interface{}) {} |
This file contains 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 log | |
import ( | |
"testing" | |
) | |
func BenchmarkDebug(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
Debugf("test") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment