Skip to content

vkd/gobenchmarks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

gobenchmarks

Benchmarks of golang code

Contents

Reflect check type

Reflect check type

$ go test -benchmem -run=NONE -bench=BenchmarkReflectCheckType -benchtime=10s
BenchmarkReflectCheckTypeInterfaceSwitch-4   	2000000000	         9.35 ns/op
BenchmarkReflectCheckTypeInterfaceIf-4       	2000000000	         9.35 ns/op
BenchmarkReflectCheckTypeEquals-4            	2000000000	         9.37 ns/op
func checkInterfaceTypeSwitch(value reflect.Value) bool {
	switch value.Interface().(type) {
	case time.Duration:
		return true
	}
	return false
}

func checkInterfaceTypeIf(value reflect.Value) bool {
	_, ok := value.Interface().(time.Duration)
	return ok
}

var typeOfTimeDuration = reflect.TypeOf(time.Duration(0))

func checkInterfaceTypeEquals(value reflect.Value) bool {
	return value.Type() == typeOfTimeDuration
}

About

Benchmarks of golang aspects

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages