firstitem

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: 1 Imported by: 0

README

First item in a loop

When you build a result using a for loop, the first item might need a specific treatment.

The most efficient solution is to use an if statement to avoid code duplication. Whatever the test, no significant difference appears.

The unfair solution doesn't take the full hypothesis into account and gets a 10% improvement.

src>go test -bench=. ./firstitem

Results

go version go1.12 windows/amd64

BenchmarkFirstItemBefore-4                 20000             86551 ns/op
BenchmarkFirstItemIfOnIndex-4              20000             88000 ns/op
BenchmarkFirstItemIfOnArray-4              20000             88107 ns/op
BenchmarkFirstItemBeforeUnfair-4           20000             70460 ns/op
PASS

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FirstItemBefore

func FirstItemBefore(a int) (l int)

func FirstItemBeforeUnfair

func FirstItemBeforeUnfair(a int) (l int)

func FirstItemIfOnArray

func FirstItemIfOnArray(a int) (l int)

func FirstItemIfOnIndex

func FirstItemIfOnIndex(a int) (l int)

Types

This section is empty.

Jump to

Keyboard shortcuts

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