arrayinit

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

Initializing an array

Initializing an array can be:

  • static
  • with a known length and make
  • using append

Comparison is unfair but sheds some light on the cost. The most efficient is obviously static. Append is extending the array and x5 the make().

The method may depend on your app requirement and/or practical constraints.

src>go test -bench=. ./arrayinit

Results

go version go1.12 windows/amd64

BenchmarkInitArrayStatic-4              2000000000               0.49 ns/op
BenchmarkInitArrayMake-4                20000000                54.6 ns/op
BenchmarkInitArrayAppendStatic-4         5000000               266 ns/op
BenchmarkInitArrayAppend-4               5000000               277 ns/op
PASS

Documentation

Overview

Arrayinit initializes an array in various ways including the unfair static method

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitArrayAppend

func InitArrayAppend() []int

Var is created and values appended

func InitArrayAppendStatic

func InitArrayAppendStatic() []int

Appending on a static var

func InitArrayMake

func InitArrayMake() []int

Array is made and filled

func InitArrayStatic

func InitArrayStatic() []int

Array is known

Types

This section is empty.

Jump to

Keyboard shortcuts

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