fcnv

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2022 License: MIT Imports: 11 Imported by: 0

README

fcnv

fcnv provides Go with fast and easy type conversion.

Conversion table

funcfromto
Atoistringint
Atoi8int8
Atoi16int16
Atoi32int32
Atoi64int64
Atouiuint
Atoui8uint8
Atoui16uint16
Atoui32uint32
Atoui64uint64
Atof32float32
Atof64float64
Atoc64complex64
Atoc128comlex128
Atob[]byte
Itoaint, int8, int16, int32, int64string
Uitoauint, uint8, uint16, uint32, uint64
Ctoacomplex64, complex128
Ftoafloat32, float64
Btoa[]byte
Byte2Int[]byteint
Int2Byteint[]byte
Byte2Bool[]bytebool
Bool2Bytebool[]byte
Bool2Intboolint
Int2Boolintbool
Bool2Uintbooluint
Uint2Booluintbool
Bool2Strboolstring
Str2Boolstringbool
Struct2Jsoninterface{}string
Datetime2Datetime.Timetime.Time
Hankaku2Zenkakustringstring
Zenkaku2Hankakustringstring
Struct2FlatMapstruct1-Lv. map[string]string
FlatMap2Struct1-Lv. map[string]stringstruct

Benchmark

Atoi* / Atoui*
  • old: BenchmarkAto(|u)i\d?ByParse(I|Ui)nt
  • new: BenchmarkNewAto(|u)i\d?
name          old time/op     new time/op    delta
Atoi-12       29.5ns ± 4%    22.9ns ± 4%  -22.23%  (p=0.000 n=72+76)
Atoi8-12      26.0ns ± 6%    20.5ns ±10%  -21.22%  (p=0.000 n=78+77)
Atoi16-12     25.3ns ± 5%    20.9ns ± 8%  -17.37%  (p=0.000 n=78+73)
Atoi32-12     25.7ns ± 9%    21.3ns ± 9%  -17.30%  (p=0.000 n=71+68)
Atoi64-12     28.9ns ± 6%    25.0ns ± 9%  -13.30%  (p=0.000 n=75+77)
Atoui-12      37.4ns ± 3%    33.2ns ± 5%  -11.23%  (p=0.000 n=67+70)
Atoui8-12     24.3ns ±12%    23.1ns ±13%   -4.92%  (p=0.000 n=72+76)
Atoui16-12    24.3ns ± 7%    22.8ns ±10%   -6.00%  (p=0.000 n=72+70)
Atoui32-12    23.5ns ± 3%    17.6ns ± 6%  -25.09%  (p=0.000 n=72+73)
Atoui64-12    25.9ns ± 7%    22.4ns ± 7%  -13.55%  (p=0.000 n=72+73)

name          old alloc/op    new alloc/op   delta
Atoi-12        2.00B ± 0%     2.00B ± 0%     ~     (all equal)
Atoi8-12       9.00B ± 0%     9.00B ± 0%     ~     (all equal)
Atoi16-12      6.00B ± 0%     6.00B ± 0%     ~     (all equal)
Atoi32-12      4.00B ± 0%     3.61B ±17%   -9.69%  (p=0.000 n=80+80)
Atoi64-12      2.00B ± 0%     2.00B ± 0%     ~     (all equal)
Atoui-12       8.00B ± 0%     8.00B ± 0%     ~     (all equal)
Atoui8-12      16.0B ± 0%     16.0B ± 0%     ~     (all equal)
Atoui16-12     12.0B ± 0%     12.0B ± 0%     ~     (all equal)
Atoui32-12     7.00B ± 0%     3.00B ± 0%  -57.14%  (p=0.000 n=80+80)
Atoui64-12     4.00B ± 0%     4.00B ± 0%     ~     (all equal)

name          old allocs/op   new allocs/op  delta
Atoi-12          0.00            0.00          ~     (all equal)
Atoi8-12         0.00            0.00          ~     (all equal)
Atoi16-12        0.00            0.00          ~     (all equal)
Atoi32-12        0.00            0.00          ~     (all equal)
Atoi64-12        0.00            0.00          ~     (all equal)
Atoui-12         0.00            0.00          ~     (all equal)
Atoui8-12        0.00            0.00          ~     (all equal)
Atoui16-12       0.00            0.00          ~     (all equal)
Atoui32-12       0.00            0.00          ~     (all equal)
Atoui64-12       0.00            0.00          ~     (all equal)

Atob / Btoa

  • old: BenchmarkCast(Atob|Btoa)
  • new: BenchmarkNew(Atob|Btoa)
name     old time/op    new time/op    delta
Atob-12    0.48ns ± 3%    0.24ns ± 8%  -49.24%  (p=0.000 n=88+90)
Btoa-12    3.66ns ±11%    0.24ns ± 0%  -93.44%  (p=0.000 n=92+68)

name     old alloc/op   new alloc/op   delta
Atob-12     0.00B          0.00B          ~     (all equal)
Btoa-12     0.00B          0.00B          ~     (all equal)

name     old allocs/op  new allocs/op  delta
Atob-12      0.00           0.00          ~     (all equal)
Btoa-12      0.00           0.00          ~     (all equal)
test
$ go test -bench Ato -o test.bin -cpuprofile=cpu.prof -benchmem -count 100 -short -timeout 60m | tee run.log
$ # go install golang.org/x/perf/cmd/benchstat@latest
$ benchstat run.log
$ pprof -http=":8888" test.bin cpu.prof

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Atob

func Atob(s string) (b []byte)

func Atoc128 added in v1.1.0

func Atoc128(s string) (ret complex128, err error)

func Atoc64 added in v1.1.0

func Atoc64(s string) (ret complex64, err error)

func Atof32

func Atof32(s string) (ret float32, err error)

func Atof64

func Atof64(s string) (ret float64, err error)

func Atoi

func Atoi(s string) (ret int, err error)

func Atoi16

func Atoi16(s string) (ret int16, err error)

func Atoi32

func Atoi32(s string) (ret int32, err error)

func Atoi64

func Atoi64(s string) (ret int64, err error)

func Atoi8

func Atoi8(s string) (ret int8, err error)

func Atoui

func Atoui(s string) (ret uint, err error)

func Atoui16

func Atoui16(s string) (ret uint16, err error)

func Atoui32

func Atoui32(s string) (ret uint32, err error)

func Atoui64

func Atoui64(s string) (ret uint64, err error)

func Atoui8

func Atoui8(s string) (ret uint8, err error)

func Bool2Byte

func Bool2Byte(bo bool) (by []byte)

func Bool2Int

func Bool2Int(b bool) (i int)

func Bool2Str

func Bool2Str(b bool) (s string)

func Bool2Uint deprecated

func Bool2Uint(b bool) (i uint)

Deprecated: Bool2Uint is discontinued in the future. Bool2Int should be used.

func Btoa

func Btoa(b []byte) (ret string)

func Byte2Bool

func Byte2Bool(by []byte) (bo bool)

func Byte2Int

func Byte2Int(b []byte) (ret int, err error)

func Ctoa added in v1.1.0

func Ctoa[cmx constraints.Complex](f cmx) (ret string)

Ctoa converts a Complex (complex64, complex128) to a string. The representation precision is complex64 compliant.

func Datetime2Date

func Datetime2Date(t time.Time) (ret time.Time)

func FlatMap2Struct added in v1.1.0

func FlatMap2Struct(flatMap map[string]string, structure any, keyDic ...map[string]string) (err error)

FlatMap2Struct deserializes a one-level map[string]string into an arbitrary structure. The one-level map[string]string uses the `json` tag of the structure entered for the key. If undefined, it substitutes the field name of the structure. If you want to specify an arbitrary key for an arbitrary field, you can specify map[string]string with the field name as key in keyDic. keyDic is used in preference to the `json` tag.

func Ftoa added in v1.1.0

func Ftoa[floatx constraints.Float](f floatx) (ret string)

Ftoa converts a Float (float32, float64) to a string. The representation precision is float64 compliant.

func Hankaku2Zenkaku

func Hankaku2Zenkaku(str string) (ret string)

func I16toa deprecated

func I16toa(i int16) (ret string)

Deprecated: I16toa is discontinued in the future. Itoa should be used.

func I32toa deprecated

func I32toa(i int32) (ret string)

Deprecated: I32toa is discontinued in the future. Itoa should be used.

func I64toa deprecated

func I64toa(i int64) (ret string)

Deprecated: I64toa is discontinued in the future. Itoa should be used.

func I8toa deprecated

func I8toa(i int8) (ret string)

Deprecated: I8toa is discontinued in the future. Itoa should be used.

func Int2Bool

func Int2Bool[INT constraints.Integer](i INT) (b bool)

func Int2Byte

func Int2Byte[intx constraints.Signed](i intx) (ret []byte)

func Itoa

func Itoa[intx constraints.Signed](i intx) (ret string)

Itoa converts an int* to a string.

func Str2Bool

func Str2Bool(s string) (ret bool, err error)

func Struct2FlatMap added in v1.1.0

func Struct2FlatMap(structure any, keyDic ...map[string]string) (ret map[string]string, err error)

Struct2FlatMap serializes a structure into a one-level map[string]string. The one-level map[string]string uses the `json` tag of the structure entered for the key. If undefined, it substitutes the field name of the structure. If you want to specify an arbitrary key for an arbitrary field, you can specify map[string]string with the field name as key in keyDic. keyDic is used in preference to the `json` tag.

func Struct2Json

func Struct2Json(structure any) (jsonStr string, err error)

func Ui16toa deprecated

func Ui16toa(ui uint16) (ret string)

Deprecated: Ui16toa is discontinued in the future. Uitoa should be used.

func Ui32toa deprecated

func Ui32toa(ui uint32) (ret string)

Deprecated: Ui32toa is discontinued in the future. Uitoa should be used.

func Ui64toa deprecated

func Ui64toa(ui uint64) (ret string)

Deprecated: Ui64toa is discontinued in the future. Uitoa should be used.

func Ui8toa deprecated

func Ui8toa(ui uint8) (ret string)

Deprecated: Ui8toa is discontinued in the future. Uitoa should be used.

func Uint2Bool deprecated

func Uint2Bool(i uint) (b bool)

Deprecated: Uint2Bool is discontinued in the future. Int2Bool should be used.

func Uitoa

func Uitoa[uintx constraints.Unsigned](ui uintx) (ret string)

Uitoa converts an uint* to a string.

func Zenkaku2Hankaku

func Zenkaku2Hankaku(str string) (ret string)

Types

This section is empty.

Jump to

Keyboard shortcuts

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