fcnv provides Go with fast and easy type conversion.
func | from | to |
---|---|---|
Atoi | string | int |
Atoi8 | int8 | |
Atoi16 | int16 | |
Atoi32 | int32 | |
Atoi64 | int64 | |
Atoui | uint | |
Atoui8 | uint8 | |
Atoui16 | uint16 | |
Atoui32 | uint32 | |
Atoui64 | uint64 | |
Atof32 | float32 | |
Atof64 | float64 | |
Atoc64 | complex64 | |
Atoc128 | comlex128 | |
Atob | []byte | |
Itoa | int, int8, int16, int32, int64 | string |
Uitoa | uint, uint8, uint16, uint32, uint64 | |
Ctoa | complex64, complex128 | |
Ftoa | float32, float64 | |
Btoa | []byte | |
Byte2Int | []byte | int |
Int2Byte | int | []byte |
Byte2Bool | []byte | bool |
Bool2Byte | bool | []byte |
Bool2Int | bool | int |
Int2Bool | int | bool |
Bool2Uint | bool | uint |
Uint2Bool | uint | bool |
Bool2Str | bool | string |
Str2Bool | string | bool |
Struct2Json | interface{} | string |
Datetime2Date | time.Time | time.Time |
Hankaku2Zenkaku | string | string |
Zenkaku2Hankaku | string | string |
Struct2FlatMap | struct | 1-Lv. map[string]string |
FlatMap2Struct | 1-Lv. map[string]string | struct |
- 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)
- 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)
$ 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