1
0
Fork 0
Helper/workaround for interface nil checks in Go with benchmarks
Go to file
Gregory Eremin 7fa581aba3 Update docs, compare to normal not-equals null check 2020-10-06 00:18:02 +02:00
LICENSE Update docs, compare to normal not-equals null check 2020-10-06 00:18:02 +02:00
README.md Update docs, compare to normal not-equals null check 2020-10-06 00:18:02 +02:00
isnil.go Initial commit 2017-07-25 17:50:44 +04:00
isnil_test.go Update docs, compare to normal not-equals null check 2020-10-06 00:18:02 +02:00

README.md

isnil

nil check that works for interfaces too. Example code and benchmarks.

Benchmarks:

#
# x != nil
#

# nil pointer
BenchmarkEqNilBasic
BenchmarkEqNilBasic-8           1000000000           0.247 ns/op

# nil interface
BenchmarkEqNilInterface
BenchmarkEqNilInterface-8       1000000000           0.247 ns/op


#
# IsNil(x)
#

# nil pointer
BenchmarkIsNilBasic
BenchmarkIsNilBasic-8           274689241            4.37 ns/op

# (*struct{})(nil)
BenchmarkIsNilInterface
BenchmarkIsNilInterface-8       277561260            4.26 ns/op

# nil
BenchmarkIsNilNil
BenchmarkIsNilNil-8             803470719            1.48 ns/op