diff options
author | Jamie Liu <jamieliu@google.com> | 2020-09-15 15:57:38 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-09-15 15:59:25 -0700 |
commit | 8b15effd9ec6091feb9ec554ebe38cc02e765560 (patch) | |
tree | 323785581a4830744fdb2753063b5031cd7216db /pkg/syserror | |
parent | 456c6c33e104e7421a5a815bba69d46b289ae724 (diff) |
Improve syserror_test.
- It's very difficult to prevent returnErrnoAsError and returnError from being
optimized out. Instead, replace BenchmarkReturn* with BenchmarkAssign*, which
store to globalError.
- Compare to a non-nil globalError in BenchmarkCompare* and BenchmarkSwitch*.
New results:
BenchmarkAssignErrno
BenchmarkAssignErrno-12 1000000000 0.615 ns/op
BenchmarkAssignError
BenchmarkAssignError-12 1000000000 0.626 ns/op
BenchmarkCompareErrno
BenchmarkCompareErrno-12 1000000000 0.522 ns/op
BenchmarkCompareError
BenchmarkCompareError-12 1000000000 3.54 ns/op
BenchmarkSwitchErrno
BenchmarkSwitchErrno-12 1000000000 1.45 ns/op
BenchmarkSwitchError
BenchmarkSwitchError-12 536315757 10.9 ns/op
PiperOrigin-RevId: 331875387
Diffstat (limited to 'pkg/syserror')
-rw-r--r-- | pkg/syserror/syserror_test.go | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/pkg/syserror/syserror_test.go b/pkg/syserror/syserror_test.go index 29719752e..7036467c4 100644 --- a/pkg/syserror/syserror_test.go +++ b/pkg/syserror/syserror_test.go @@ -24,27 +24,20 @@ import ( var globalError error -func returnErrnoAsError() error { - return syscall.EINVAL -} - -func returnError() error { - return syserror.EINVAL -} - -func BenchmarkReturnErrnoAsError(b *testing.B) { +func BenchmarkAssignErrno(b *testing.B) { for i := b.N; i > 0; i-- { - returnErrnoAsError() + globalError = syscall.EINVAL } } -func BenchmarkReturnError(b *testing.B) { +func BenchmarkAssignError(b *testing.B) { for i := b.N; i > 0; i-- { - returnError() + globalError = syserror.EINVAL } } func BenchmarkCompareErrno(b *testing.B) { + globalError = syscall.EAGAIN j := 0 for i := b.N; i > 0; i-- { if globalError == syscall.EINVAL { @@ -54,6 +47,7 @@ func BenchmarkCompareErrno(b *testing.B) { } func BenchmarkCompareError(b *testing.B) { + globalError = syserror.EAGAIN j := 0 for i := b.N; i > 0; i-- { if globalError == syserror.EINVAL { @@ -63,6 +57,7 @@ func BenchmarkCompareError(b *testing.B) { } func BenchmarkSwitchErrno(b *testing.B) { + globalError = syscall.EPERM j := 0 for i := b.N; i > 0; i-- { switch globalError { @@ -77,6 +72,7 @@ func BenchmarkSwitchErrno(b *testing.B) { } func BenchmarkSwitchError(b *testing.B) { + globalError = syserror.EPERM j := 0 for i := b.N; i > 0; i-- { switch globalError { |