Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

common/bitutil: use result of TestBytes to prevent dead code elimination #19846

Merged
merged 1 commit into from
Jul 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions common/bitutil/bitutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,16 +190,20 @@ func benchmarkBaseOR(b *testing.B, size int) {
}
}

var GloBool bool // Exported global will not be dead-code eliminated, at least not yet.

// Benchmarks the potentially optimized bit testing performance.
func BenchmarkFastTest1KB(b *testing.B) { benchmarkFastTest(b, 1024) }
func BenchmarkFastTest2KB(b *testing.B) { benchmarkFastTest(b, 2048) }
func BenchmarkFastTest4KB(b *testing.B) { benchmarkFastTest(b, 4096) }

func benchmarkFastTest(b *testing.B, size int) {
p := make([]byte, size)
a := false
for i := 0; i < b.N; i++ {
TestBytes(p)
a = a != TestBytes(p)
}
GloBool = a // Use of benchmark "result" to prevent total dead code elimination.
}

// Benchmarks the baseline bit testing performance.
Expand All @@ -209,7 +213,9 @@ func BenchmarkBaseTest4KB(b *testing.B) { benchmarkBaseTest(b, 4096) }

func benchmarkBaseTest(b *testing.B, size int) {
p := make([]byte, size)
a := false
for i := 0; i < b.N; i++ {
safeTestBytes(p)
a = a != safeTestBytes(p)
}
GloBool = a // Use of benchmark "result" to prevent total dead code elimination.
}