Skip to content

Latest commit

 

History

History
113 lines (102 loc) · 5.04 KB

README.md

File metadata and controls

113 lines (102 loc) · 5.04 KB

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