Skip to content

Commit

Permalink
feat: improve parsing (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
quagmt authored Oct 27, 2024
1 parent 57575fe commit 86caf9b
Show file tree
Hide file tree
Showing 14 changed files with 289 additions and 124 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fuzz-all:
@sh scripts/fuzz-all.sh $(fuzzTime)

bench:
@go test -bench=BenchmarkMarshalJSON -benchmem -benchmem -memprofile=mem.out -cpuprofile=cpu.out -run NONE
@go test -bench=BenchmarkString -benchmem -benchmem -memprofile=mem.out -cpuprofile=cpu.out -run NONE

# https://stackoverflow.com/questions/6273608/how-to-pass-argument-to-makefile-from-command-line
%:
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

bench:
# @go test -bench BenchmarkMarshalJSON -benchmem -memprofile mem.out -cpuprofile cpu.out -run NONE
@go test -bench BenchmarkDiv -benchmem -count=10 -run NONE > new.txt
@go test -bench BenchmarkParse -benchmem -count=10 -run NONE > new.txt

bench-udec:
@rm -f bench-udec.txt
Expand Down
6 changes: 3 additions & 3 deletions benchmarks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ BenchmarkPow/1.01.Pow(10)-32
BenchmarkPow/1.01.Pow(100)-32 994129 1137 ns/op 817 B/op 13 allocs/op
# Parsing string
BenchmarkParse/1234567890123456789.1234567890123456879-32 15700467 78.16 ns/op 0 B/op 0 allocs/op
BenchmarkParse/1234567890-32 54752288 22.86 ns/op 0 B/op 0 allocs/op
BenchmarkParse/0.1234567890123456879-32 28947921 41.76 ns/op 0 B/op 0 allocs/op
BenchmarkParse/1234567890123456789.1234567890123456879-32 32111433 38.21 ns/op 0 B/op 0 allocs/op
BenchmarkParse/1234567890-32 98585916 12.58 ns/op 0 B/op 0 allocs/op
BenchmarkParse/0.1234567890123456879-32 44339668 26.45 ns/op 0 B/op 0 allocs/op
BenchmarkParseFallBack/123456789123456789123456.1234567890123456-32 2805122 473.3 ns/op 192 B/op 6 allocs/op
BenchmarkParseFallBack/111222333444555666777888999.1234567890123456789-32 2442004 500.8 ns/op 216 B/op 6 allocs/op
BenchmarkString/1234567890123456789.1234567890123456879-32 12797790 98.69 ns/op 48 B/op 1 allocs/op
Expand Down
10 changes: 10 additions & 0 deletions benchmarks/bench-ss.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ BenchmarkParse/0.1234567890123456879-32 4524166
BenchmarkParse/0.1234567890123456879-32 4930246 243.4 ns/op 144 B/op 5 allocs/op
BenchmarkParse/0.1234567890123456879-32 4491036 241.7 ns/op 144 B/op 5 allocs/op
BenchmarkParse/0.1234567890123456879-32 4911284 219.5 ns/op 144 B/op 5 allocs/op
BenchmarkParse/12345678901234567890123456789.123-32 3649983 313.6 ns/op 152 B/op 5 allocs/op
BenchmarkParse/12345678901234567890123456789.123-32 4065206 310.8 ns/op 152 B/op 5 allocs/op
BenchmarkParse/12345678901234567890123456789.123-32 3553578 293.6 ns/op 152 B/op 5 allocs/op
BenchmarkParse/12345678901234567890123456789.123-32 4134546 326.1 ns/op 152 B/op 5 allocs/op
BenchmarkParse/12345678901234567890123456789.123-32 3722556 294.2 ns/op 152 B/op 5 allocs/op
BenchmarkParse/12345678901234567890123456789.123-32 3730910 337.1 ns/op 152 B/op 5 allocs/op
BenchmarkParse/12345678901234567890123456789.123-32 4160892 308.3 ns/op 152 B/op 5 allocs/op
BenchmarkParse/12345678901234567890123456789.123-32 3727047 301.0 ns/op 152 B/op 5 allocs/op
BenchmarkParse/12345678901234567890123456789.123-32 3756850 342.8 ns/op 152 B/op 5 allocs/op
BenchmarkParse/12345678901234567890123456789.123-32 3766802 335.8 ns/op 152 B/op 5 allocs/op
BenchmarkParseFallBack/123456789123456789123456.1234567890123456-32 3580087 325.3 ns/op 168 B/op 5 allocs/op
BenchmarkParseFallBack/123456789123456789123456.1234567890123456-32 3728620 309.6 ns/op 168 B/op 5 allocs/op
BenchmarkParseFallBack/123456789123456789123456.1234567890123456-32 3925362 328.2 ns/op 168 B/op 5 allocs/op
Expand Down
110 changes: 60 additions & 50 deletions benchmarks/bench-udec.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,66 @@ goos: linux
goarch: amd64
pkg: github.com/quagmt/udecimal/benchmarks
cpu: Intel(R) Core(TM) i9-14900HX
BenchmarkParse/1234567890123456789.1234567890123456879-32 14480929 70.79 ns/op 0 B/op 0 allocs/op
BenchmarkParse/1234567890123456789.1234567890123456879-32 15750946 76.10 ns/op 0 B/op 0 allocs/op
BenchmarkParse/1234567890123456789.1234567890123456879-32 13101150 84.18 ns/op 0 B/op 0 allocs/op
BenchmarkParse/1234567890123456789.1234567890123456879-32 14365287 78.62 ns/op 0 B/op 0 allocs/op
BenchmarkParse/1234567890123456789.1234567890123456879-32 12634765 82.26 ns/op 0 B/op 0 allocs/op
BenchmarkParse/1234567890123456789.1234567890123456879-32 13364164 82.76 ns/op 0 B/op 0 allocs/op
BenchmarkParse/1234567890123456789.1234567890123456879-32 15356986 79.13 ns/op 0 B/op 0 allocs/op
BenchmarkParse/1234567890123456789.1234567890123456879-32 15347952 78.36 ns/op 0 B/op 0 allocs/op
BenchmarkParse/1234567890123456789.1234567890123456879-32 16158620 76.31 ns/op 0 B/op 0 allocs/op
BenchmarkParse/1234567890123456789.1234567890123456879-32 15837738 86.18 ns/op 0 B/op 0 allocs/op
BenchmarkParse/123-32 132207692 9.652 ns/op 0 B/op 0 allocs/op
BenchmarkParse/123-32 129531774 9.824 ns/op 0 B/op 0 allocs/op
BenchmarkParse/123-32 139214372 9.509 ns/op 0 B/op 0 allocs/op
BenchmarkParse/123-32 128602180 9.571 ns/op 0 B/op 0 allocs/op
BenchmarkParse/123-32 128681630 8.761 ns/op 0 B/op 0 allocs/op
BenchmarkParse/123-32 131462078 8.950 ns/op 0 B/op 0 allocs/op
BenchmarkParse/123-32 140413305 8.689 ns/op 0 B/op 0 allocs/op
BenchmarkParse/123-32 131624270 8.995 ns/op 0 B/op 0 allocs/op
BenchmarkParse/123-32 141288943 9.431 ns/op 0 B/op 0 allocs/op
BenchmarkParse/123-32 128163589 9.337 ns/op 0 B/op 0 allocs/op
BenchmarkParse/123456.123456-32 40123141 27.87 ns/op 0 B/op 0 allocs/op
BenchmarkParse/123456.123456-32 46144542 26.20 ns/op 0 B/op 0 allocs/op
BenchmarkParse/123456.123456-32 46774532 25.98 ns/op 0 B/op 0 allocs/op
BenchmarkParse/123456.123456-32 43839273 24.81 ns/op 0 B/op 0 allocs/op
BenchmarkParse/123456.123456-32 50633299 24.72 ns/op 0 B/op 0 allocs/op
BenchmarkParse/123456.123456-32 53245113 24.46 ns/op 0 B/op 0 allocs/op
BenchmarkParse/123456.123456-32 49705689 23.29 ns/op 0 B/op 0 allocs/op
BenchmarkParse/123456.123456-32 50949015 24.66 ns/op 0 B/op 0 allocs/op
BenchmarkParse/123456.123456-32 52628265 22.96 ns/op 0 B/op 0 allocs/op
BenchmarkParse/123456.123456-32 51431748 23.50 ns/op 0 B/op 0 allocs/op
BenchmarkParse/1234567890-32 50591940 20.63 ns/op 0 B/op 0 allocs/op
BenchmarkParse/1234567890-32 50563016 21.10 ns/op 0 B/op 0 allocs/op
BenchmarkParse/1234567890-32 55656282 20.80 ns/op 0 B/op 0 allocs/op
BenchmarkParse/1234567890-32 58230686 21.70 ns/op 0 B/op 0 allocs/op
BenchmarkParse/1234567890-32 55902580 21.93 ns/op 0 B/op 0 allocs/op
BenchmarkParse/1234567890-32 56100603 21.60 ns/op 0 B/op 0 allocs/op
BenchmarkParse/1234567890-32 53920798 21.77 ns/op 0 B/op 0 allocs/op
BenchmarkParse/1234567890-32 55861123 22.21 ns/op 0 B/op 0 allocs/op
BenchmarkParse/1234567890-32 54120472 21.64 ns/op 0 B/op 0 allocs/op
BenchmarkParse/1234567890-32 60566383 20.49 ns/op 0 B/op 0 allocs/op
BenchmarkParse/0.1234567890123456879-32 28710724 43.22 ns/op 0 B/op 0 allocs/op
BenchmarkParse/0.1234567890123456879-32 29146560 44.10 ns/op 0 B/op 0 allocs/op
BenchmarkParse/0.1234567890123456879-32 26922684 43.90 ns/op 0 B/op 0 allocs/op
BenchmarkParse/0.1234567890123456879-32 27707344 40.65 ns/op 0 B/op 0 allocs/op
BenchmarkParse/0.1234567890123456879-32 28752571 40.60 ns/op 0 B/op 0 allocs/op
BenchmarkParse/0.1234567890123456879-32 28529010 42.58 ns/op 0 B/op 0 allocs/op
BenchmarkParse/0.1234567890123456879-32 29355486 42.93 ns/op 0 B/op 0 allocs/op
BenchmarkParse/0.1234567890123456879-32 29871193 40.69 ns/op 0 B/op 0 allocs/op
BenchmarkParse/0.1234567890123456879-32 29841739 40.72 ns/op 0 B/op 0 allocs/op
BenchmarkParse/0.1234567890123456879-32 29470508 42.17 ns/op 0 B/op 0 allocs/op
BenchmarkParse/1234567890123456789.1234567890123456879-32 32111433 38.21 ns/op 0 B/op 0 allocs/op
BenchmarkParse/1234567890123456789.1234567890123456879-32 30370411 38.00 ns/op 0 B/op 0 allocs/op
BenchmarkParse/1234567890123456789.1234567890123456879-32 30983041 40.51 ns/op 0 B/op 0 allocs/op
BenchmarkParse/1234567890123456789.1234567890123456879-32 29734609 40.17 ns/op 0 B/op 0 allocs/op
BenchmarkParse/1234567890123456789.1234567890123456879-32 32103327 38.89 ns/op 0 B/op 0 allocs/op
BenchmarkParse/1234567890123456789.1234567890123456879-32 31406709 39.94 ns/op 0 B/op 0 allocs/op
BenchmarkParse/1234567890123456789.1234567890123456879-32 32262856 38.02 ns/op 0 B/op 0 allocs/op
BenchmarkParse/1234567890123456789.1234567890123456879-32 29613183 37.88 ns/op 0 B/op 0 allocs/op
BenchmarkParse/1234567890123456789.1234567890123456879-32 31656368 38.01 ns/op 0 B/op 0 allocs/op
BenchmarkParse/1234567890123456789.1234567890123456879-32 29451500 39.32 ns/op 0 B/op 0 allocs/op
BenchmarkParse/123-32 141880339 8.397 ns/op 0 B/op 0 allocs/op
BenchmarkParse/123-32 144087966 8.803 ns/op 0 B/op 0 allocs/op
BenchmarkParse/123-32 141612804 8.804 ns/op 0 B/op 0 allocs/op
BenchmarkParse/123-32 148056843 8.653 ns/op 0 B/op 0 allocs/op
BenchmarkParse/123-32 134661038 8.253 ns/op 0 B/op 0 allocs/op
BenchmarkParse/123-32 146080090 8.784 ns/op 0 B/op 0 allocs/op
BenchmarkParse/123-32 140681473 8.868 ns/op 0 B/op 0 allocs/op
BenchmarkParse/123-32 147862611 8.554 ns/op 0 B/op 0 allocs/op
BenchmarkParse/123-32 149067693 8.194 ns/op 0 B/op 0 allocs/op
BenchmarkParse/123-32 139148565 8.671 ns/op 0 B/op 0 allocs/op
BenchmarkParse/123456.123456-32 76273048 15.31 ns/op 0 B/op 0 allocs/op
BenchmarkParse/123456.123456-32 83309959 14.66 ns/op 0 B/op 0 allocs/op
BenchmarkParse/123456.123456-32 69696046 15.22 ns/op 0 B/op 0 allocs/op
BenchmarkParse/123456.123456-32 87739012 14.25 ns/op 0 B/op 0 allocs/op
BenchmarkParse/123456.123456-32 84302694 15.17 ns/op 0 B/op 0 allocs/op
BenchmarkParse/123456.123456-32 86778757 14.38 ns/op 0 B/op 0 allocs/op
BenchmarkParse/123456.123456-32 87325648 14.65 ns/op 0 B/op 0 allocs/op
BenchmarkParse/123456.123456-32 82021698 13.88 ns/op 0 B/op 0 allocs/op
BenchmarkParse/123456.123456-32 83819546 14.01 ns/op 0 B/op 0 allocs/op
BenchmarkParse/123456.123456-32 85760779 14.93 ns/op 0 B/op 0 allocs/op
BenchmarkParse/1234567890-32 100000000 12.30 ns/op 0 B/op 0 allocs/op
BenchmarkParse/1234567890-32 98585916 12.58 ns/op 0 B/op 0 allocs/op
BenchmarkParse/1234567890-32 100000000 12.40 ns/op 0 B/op 0 allocs/op
BenchmarkParse/1234567890-32 96808634 12.44 ns/op 0 B/op 0 allocs/op
BenchmarkParse/1234567890-32 100000000 12.29 ns/op 0 B/op 0 allocs/op
BenchmarkParse/1234567890-32 91031727 12.68 ns/op 0 B/op 0 allocs/op
BenchmarkParse/1234567890-32 93970161 12.66 ns/op 0 B/op 0 allocs/op
BenchmarkParse/1234567890-32 96205394 12.25 ns/op 0 B/op 0 allocs/op
BenchmarkParse/1234567890-32 99670058 11.67 ns/op 0 B/op 0 allocs/op
BenchmarkParse/1234567890-32 95630294 11.83 ns/op 0 B/op 0 allocs/op
BenchmarkParse/0.1234567890123456879-32 44339668 26.45 ns/op 0 B/op 0 allocs/op
BenchmarkParse/0.1234567890123456879-32 45756302 24.08 ns/op 0 B/op 0 allocs/op
BenchmarkParse/0.1234567890123456879-32 48353757 25.04 ns/op 0 B/op 0 allocs/op
BenchmarkParse/0.1234567890123456879-32 46825815 27.06 ns/op 0 B/op 0 allocs/op
BenchmarkParse/0.1234567890123456879-32 49001607 25.61 ns/op 0 B/op 0 allocs/op
BenchmarkParse/0.1234567890123456879-32 49650522 26.46 ns/op 0 B/op 0 allocs/op
BenchmarkParse/0.1234567890123456879-32 45742516 26.07 ns/op 0 B/op 0 allocs/op
BenchmarkParse/0.1234567890123456879-32 47493613 25.55 ns/op 0 B/op 0 allocs/op
BenchmarkParse/0.1234567890123456879-32 46787036 25.79 ns/op 0 B/op 0 allocs/op
BenchmarkParse/0.1234567890123456879-32 49189808 26.09 ns/op 0 B/op 0 allocs/op
BenchmarkParse/12345678901234567890123456789.123-32 20359177 62.64 ns/op 0 B/op 0 allocs/op
BenchmarkParse/12345678901234567890123456789.123-32 20100522 62.59 ns/op 0 B/op 0 allocs/op
BenchmarkParse/12345678901234567890123456789.123-32 19438142 63.89 ns/op 0 B/op 0 allocs/op
BenchmarkParse/12345678901234567890123456789.123-32 18644307 59.72 ns/op 0 B/op 0 allocs/op
BenchmarkParse/12345678901234567890123456789.123-32 19709970 62.42 ns/op 0 B/op 0 allocs/op
BenchmarkParse/12345678901234567890123456789.123-32 19311558 59.00 ns/op 0 B/op 0 allocs/op
BenchmarkParse/12345678901234567890123456789.123-32 20234343 59.28 ns/op 0 B/op 0 allocs/op
BenchmarkParse/12345678901234567890123456789.123-32 20193010 63.77 ns/op 0 B/op 0 allocs/op
BenchmarkParse/12345678901234567890123456789.123-32 18147177 61.41 ns/op 0 B/op 0 allocs/op
BenchmarkParse/12345678901234567890123456789.123-32 19687285 61.19 ns/op 0 B/op 0 allocs/op
BenchmarkParseFallBack/123456789123456789123456.1234567890123456-32 2585487 479.9 ns/op 192 B/op 6 allocs/op
BenchmarkParseFallBack/123456789123456789123456.1234567890123456-32 2280304 507.8 ns/op 192 B/op 6 allocs/op
BenchmarkParseFallBack/123456789123456789123456.1234567890123456-32 3002433 497.9 ns/op 192 B/op 6 allocs/op
Expand Down
1 change: 1 addition & 0 deletions benchmarks/benchmarks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func BenchmarkParse(b *testing.B) {
"123456.123456",
"1234567890",
"0.1234567890123456879",
"12345678901234567890123456789.123",
}

for _, tc := range testcases {
Expand Down
Loading

0 comments on commit 86caf9b

Please sign in to comment.