isvalid

package
v0.0.0-...-b91b1e7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 24, 2019 License: BSD-2-Clause Imports: 0 Imported by: 0

README

Local boolean

Checking a sequence of boolean conditions:

  • individually with a boolean in func scope
  • individually with a boolean in if scope
  • inside a for loop using a bool in func scope
  • inside a for loop shadowing a bool in if scope

The example is theoretical and should prevent compiler optimization of the tests applied to each value.

If the if instructions are in sequence, var creation inside the if is expensive. Inside a for loop for a sequence of tests of the same size, shadowing is so optimized that you don't need to bother.

src>go test -bench=. ./isvalid

Results

go version go1.12 windows/amd64

BenchmarkCheckValueFuncVar-4    20000000                80.3 ns/op
BenchmarkCheckValueIfVar-4      20000000                82.2 ns/op
BenchmarkCheckValueForFunc-4    20000000                88.9 ns/op
BenchmarkCheckValueForIf-4      20000000                85.3 ns/op
PASS

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckValueForFunc

func CheckValueForFunc(test []int) (s []int)

func CheckValueForIf

func CheckValueForIf(test []int) (s []int)

func CheckValueFuncVar

func CheckValueFuncVar(test []int) (s []int)

func CheckValueIfVar

func CheckValueIfVar(test []int) (s []int)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL