@@ -14,6 +14,7 @@ In order for you to benefit from it too, I will publish such benchmarks in this
14
14
* [ foreach] ( https://github.com/SimonWaldherr/golang-benchmarks#foreach )
15
15
* [ hash] ( https://github.com/SimonWaldherr/golang-benchmarks#hash )
16
16
* [ index] ( https://github.com/SimonWaldherr/golang-benchmarks#index )
17
+ * [ json] ( https://github.com/SimonWaldherr/golang-benchmarks#json )
17
18
* [ math] ( https://github.com/SimonWaldherr/golang-benchmarks#math )
18
19
* [ parse] ( https://github.com/SimonWaldherr/golang-benchmarks#parse )
19
20
* [ random] ( https://github.com/SimonWaldherr/golang-benchmarks#random )
@@ -36,6 +37,8 @@ If you\'re interested in new programming languages, you should definitely take a
36
37
37
38
## Benchmark Results
38
39
40
+ Golang Version: go version go1.13.3 darwin/amd64
41
+
39
42
### base64
40
43
41
44
``` go
@@ -85,10 +88,10 @@ func BenchmarkBase64regex(b *testing.B) {
85
88
$ go test -bench . -benchmem
86
89
goos: darwin
87
90
goarch: amd64
88
- BenchmarkBase64decode-8 10000000 174 ns/op 40 B/op 3 allocs/op
89
- BenchmarkBase64regex-8 50000 37282 ns/op 98160 B/op 218 allocs/op
91
+ BenchmarkBase64decode-8 8689669 139 ns/op 40 B/op 3 allocs/op
92
+ BenchmarkBase64regex-8 50638 22595 ns/op 21421 B/op 198 allocs/op
90
93
PASS
91
- ok _/Users/simonwaldherr/git/golang-benchmarks/base64 4.188s
94
+ ok _/Users/simonwaldherr/git/golang-benchmarks/base64 3.749s
92
95
```
93
96
94
97
### between
@@ -180,12 +183,12 @@ func BenchmarkFulltextParse(b *testing.B) {
180
183
$ go test -bench . -benchmem
181
184
goos: darwin
182
185
goarch: amd64
183
- BenchmarkNumberRegEx-8 50000 29216 ns/op 92176 B/op 162 allocs/op
184
- BenchmarkFulltextRegEx-8 100000 23527 ns/op 87680 B/op 124 allocs/op
185
- BenchmarkNumberParse-8 30000000 59.8 ns/op 0 B/op 0 allocs/op
186
- BenchmarkFulltextParse-8 1000000 1232 ns/op 32 B/op 2 allocs/op
186
+ BenchmarkNumberRegEx-8 79514 17505 ns/op 16093 B/op 142 allocs/op
187
+ BenchmarkFulltextRegEx-8 98248 11876 ns/op 11579 B/op 104 allocs/op
188
+ BenchmarkNumberParse-8 15141446 80.1 ns/op 0 B/op 0 allocs/op
189
+ BenchmarkFulltextParse-8 1000000 1061 ns/op 32 B/op 2 allocs/op
187
190
PASS
188
- ok _/Users/simonwaldherr/git/golang-benchmarks/between 7.470s
191
+ ok _/Users/simonwaldherr/git/golang-benchmarks/between 8.005s
189
192
```
190
193
191
194
### concat
@@ -231,11 +234,11 @@ func BenchmarkConcatBuilder(b *testing.B) {
231
234
$ go test -bench . -benchmem
232
235
goos: darwin
233
236
goarch: amd64
234
- BenchmarkConcatString-8 1000000 55018 ns/op 503992 B/op 1 allocs/op
235
- BenchmarkConcatBuffer-8 200000000 9.81 ns/op 2 B/op 0 allocs/op
236
- BenchmarkConcatBuilder-8 1000000000 3.90 ns/op 6 B/op 0 allocs/op
237
+ BenchmarkConcatString-8 1000000 51987 ns/op 503994 B/op 1 allocs/op
238
+ BenchmarkConcatBuffer-8 137715688 7.91 ns/op 3 B/op 0 allocs/op
239
+ BenchmarkConcatBuilder-8 575587425 2.86 ns/op 5 B/op 0 allocs/op
237
240
PASS
238
- ok _/Users/simonwaldherr/git/golang-benchmarks/concat 62.394s
241
+ ok _/Users/simonwaldherr/git/golang-benchmarks/concat 56.321s
239
242
```
240
243
241
244
### contains
@@ -385,16 +388,16 @@ func BenchmarkMatchNot(b *testing.B) {
385
388
$ go test -bench . -benchmem
386
389
goos: darwin
387
390
goarch: amd64
388
- BenchmarkContains-8 100000000 15.2 ns/op 0 B/op 0 allocs/op
389
- BenchmarkContainsNot-8 100000000 14.0 ns/op 0 B/op 0 allocs/op
390
- BenchmarkContainsBytes-8 50000000 26.2 ns/op 0 B/op 0 allocs/op
391
- BenchmarkContainsBytesNot-8 50000000 28.0 ns/op 0 B/op 0 allocs/op
392
- BenchmarkCompileMatch-8 10000000 137 ns/op 0 B/op 0 allocs/op
393
- BenchmarkCompileMatchNot-8 20000000 73.4 ns/op 0 B/op 0 allocs/op
394
- BenchmarkMatch-8 300000 7201 ns/op 38912 B/op 27 allocs/op
395
- BenchmarkMatchNot-8 300000 6383 ns/op 38912 B/op 27 allocs/op
391
+ BenchmarkContains-8 137404404 8.78 ns/op 0 B/op 0 allocs/op
392
+ BenchmarkContainsNot-8 141748958 8.32 ns/op 0 B/op 0 allocs/op
393
+ BenchmarkContainsBytes-8 126635754 9.82 ns/op 0 B/op 0 allocs/op
394
+ BenchmarkContainsBytesNot-8 121881022 9.77 ns/op 0 B/op 0 allocs/op
395
+ BenchmarkCompileMatch-8 11328054 105 ns/op 0 B/op 0 allocs/op
396
+ BenchmarkCompileMatchNot-8 23368893 51.0 ns/op 0 B/op 0 allocs/op
397
+ BenchmarkMatch-8 660074 1627 ns/op 1362 B/op 17 allocs/op
398
+ BenchmarkMatchNot-8 707730 1537 ns/op 1362 B/op 17 allocs/op
396
399
PASS
397
- ok _/Users/simonwaldherr/git/golang-benchmarks/contains 12.979s
400
+ ok _/Users/simonwaldherr/git/golang-benchmarks/contains 16.158s
398
401
```
399
402
400
403
### foreach
@@ -481,12 +484,12 @@ func BenchmarkRangeSliceKey(b *testing.B) {
481
484
$ go test -bench . -benchmem
482
485
goos: darwin
483
486
goarch: amd64
484
- BenchmarkForMap-8 50000000 31.4 ns/op 0 B/op 0 allocs/op
485
- BenchmarkRangeMap-8 20000000 87.4 ns/op 0 B/op 0 allocs/op
486
- BenchmarkRangeSlice-8 500000000 4.05 ns/op 0 B/op 0 allocs/op
487
- BenchmarkRangeSliceKey-8 300000000 4.41 ns/op 0 B/op 0 allocs/op
487
+ BenchmarkForMap-8 48077392 26.0 ns/op 0 B/op 0 allocs/op
488
+ BenchmarkRangeMap-8 15363625 74.6 ns/op 0 B/op 0 allocs/op
489
+ BenchmarkRangeSlice-8 310208679 3.85 ns/op 0 B/op 0 allocs/op
490
+ BenchmarkRangeSliceKey-8 308933263 3.97 ns/op 0 B/op 0 allocs/op
488
491
PASS
489
- ok _/Users/simonwaldherr/git/golang-benchmarks/foreach 7.654s
492
+ ok _/Users/simonwaldherr/git/golang-benchmarks/foreach 6.098s
490
493
```
491
494
492
495
### hash
@@ -568,18 +571,18 @@ func BenchmarkWhirlpool(b *testing.B) {
568
571
$ go test -bench . -benchmem
569
572
goos: darwin
570
573
goarch: amd64
571
- BenchmarkAdler32-8 1000000 1075 ns/op 8 B/op 1 allocs/op
572
- BenchmarkCRC32-8 10000000 167 ns/op 8 B/op 1 allocs/op
573
- BenchmarkFnv128-8 200000 9565 ns/op 16 B/op 1 allocs/op
574
- BenchmarkMD5-8 500000 3532 ns/op 16 B/op 1 allocs/op
575
- BenchmarkSHA1-8 500000 2627 ns/op 32 B/op 1 allocs/op
576
- BenchmarkSHA256-8 200000 6406 ns/op 32 B/op 1 allocs/op
577
- BenchmarkSHA512-8 300000 4352 ns/op 64 B/op 1 allocs/op
578
- BenchmarkSHA3256-8 200000 8150 ns/op 512 B/op 3 allocs/op
579
- BenchmarkSHA3512-8 100000 13825 ns/op 576 B/op 3 allocs/op
580
- BenchmarkWhirlpool-8 20000 85973 ns/op 64 B/op 1 allocs/op
574
+ BenchmarkAdler32-8 1414144 854 ns/op 8 B/op 1 allocs/op
575
+ BenchmarkCRC32-8 7998510 152 ns/op 8 B/op 1 allocs/op
576
+ BenchmarkFnv128-8 229381 5199 ns/op 16 B/op 1 allocs/op
577
+ BenchmarkMD5-8 369140 3140 ns/op 16 B/op 1 allocs/op
578
+ BenchmarkSHA1-8 412408 2645 ns/op 32 B/op 1 allocs/op
579
+ BenchmarkSHA256-8 205897 5854 ns/op 32 B/op 1 allocs/op
580
+ BenchmarkSHA512-8 272835 4391 ns/op 64 B/op 1 allocs/op
581
+ BenchmarkSHA3256-8 154688 7670 ns/op 512 B/op 3 allocs/op
582
+ BenchmarkSHA3512-8 75841 16354 ns/op 576 B/op 3 allocs/op
583
+ BenchmarkWhirlpool-8 18272 65319 ns/op 64 B/op 1 allocs/op
581
584
PASS
582
- ok _/Users/simonwaldherr/git/golang-benchmarks/hash 16.537s
585
+ ok _/Users/simonwaldherr/git/golang-benchmarks/hash 14.421s
583
586
```
584
587
585
588
### index
@@ -662,10 +665,104 @@ func BenchmarkMapIntKeys(b *testing.B) {
662
665
$ go test -bench . -benchmem
663
666
goos: darwin
664
667
goarch: amd64
665
- BenchmarkMapStringKeys-8 10000000 119 ns/op 0 B/op 0 allocs/op
666
- BenchmarkMapIntKeys-8 20000000 80.3 ns/op 0 B/op 0 allocs/op
668
+ BenchmarkMapStringKeys-8 10594664 115 ns/op 0 B/op 0 allocs/op
669
+ BenchmarkMapIntKeys-8 15215637 75.9 ns/op 0 B/op 0 allocs/op
670
+ PASS
671
+ ok _/Users/simonwaldherr/git/golang-benchmarks/index 4.415s
672
+ ```
673
+
674
+ ### json
675
+
676
+ ``` go
677
+ package json
678
+
679
+ import (
680
+ " encoding/json"
681
+ " math"
682
+ " math/big"
683
+ " testing"
684
+ " time"
685
+ )
686
+
687
+ type Data struct {
688
+ String string
689
+ Time time.Time
690
+ Int int
691
+ Int8 int8
692
+ Int16 int16
693
+ Int32 int32
694
+ Int64 int64
695
+ Boolean bool
696
+ Float32 float32
697
+ Float64 float64
698
+ BigInt big.Int
699
+ BigFloat big.Float
700
+ }
701
+
702
+ func BenchmarkJsonMarshal (b *testing .B ) {
703
+ for n := 0 ; n < b.N ; n++ {
704
+ var d = Data{
705
+ String: " " ,
706
+ Time: time.Now (),
707
+ Int: math.MaxInt32 ,
708
+ Int8: math.MaxInt8 ,
709
+ Int16: math.MaxInt16 ,
710
+ Int32: math.MaxInt32 ,
711
+ Int64: math.MaxInt64 ,
712
+ Boolean: false ,
713
+ Float32: math.MaxFloat32 ,
714
+ Float64: math.MaxFloat64 ,
715
+ BigInt: *big.NewInt (math.MaxInt64 ),
716
+ BigFloat: *big.NewFloat (math.MaxFloat64 ),
717
+ }
718
+
719
+ _ , err := json.Marshal (d)
720
+ if err != nil {
721
+ b.Error (err)
722
+ b.Fail ()
723
+ return
724
+ }
725
+ }
726
+ }
727
+
728
+ func BenchmarkJsonUnmarshal (b *testing .B ) {
729
+ str := `
730
+ {
731
+ "String": "",
732
+ "Time": "2019-10-30T16:41:29.853426+07:00",
733
+ "Int": 2147483647,
734
+ "Int8": 127,
735
+ "Int16": 32767,
736
+ "Int32": 2147483647,
737
+ "Int64": 9223372036854775807,
738
+ "Boolean": false,
739
+ "Float32": 3.4028235e+38,
740
+ "Float64": 1.7976931348623157e+308,
741
+ "BigInt": 9999999999999999999,
742
+ "BigFloat": "2.7976931348623157e+308"
743
+ }
744
+ `
745
+
746
+ for n := 0 ; n < b.N ; n++ {
747
+ var d Data
748
+ err := json.Unmarshal ([]byte (str), &d)
749
+ if err != nil {
750
+ b.Error (err)
751
+ b.Fail ()
752
+ return
753
+ }
754
+ }
755
+ }
756
+ ```
757
+
758
+ ```
759
+ $ go test -bench . -benchmem
760
+ goos: darwin
761
+ goarch: amd64
762
+ BenchmarkJsonMarshal-8 557385 2157 ns/op 544 B/op 6 allocs/op
763
+ BenchmarkJsonUnmarshal-8 144934 8452 ns/op 2128 B/op 38 allocs/op
667
764
PASS
668
- ok _/Users/simonwaldherr/git/golang-benchmarks/index 5.078s
765
+ ok _/Users/simonwaldherr/git/golang-benchmarks/json 3.923s
669
766
```
670
767
671
768
### math
@@ -748,16 +845,16 @@ func BenchmarkMathFloat64(b *testing.B) {
748
845
$ go test -bench . -benchmem
749
846
goos: darwin
750
847
goarch: amd64
751
- BenchmarkMathInt8-8 2000000000 0.37 ns/op 0 B/op 0 allocs/op
752
- BenchmarkMathInt32-8 2000000000 0.66 ns/op 0 B/op 0 allocs/op
753
- BenchmarkMathInt64-8 2000000000 0.32 ns/op 0 B/op 0 allocs/op
754
- BenchmarkMathAtomicInt32-8 300000000 5.55 ns/op 0 B/op 0 allocs/op
755
- BenchmarkMathAtomicInt64-8 300000000 5.84 ns/op 0 B/op 0 allocs/op
756
- BenchmarkMathMutexInt-8 100000000 16.9 ns/op 0 B/op 0 allocs/op
757
- BenchmarkMathFloat32-8 2000000000 0.79 ns/op 0 B/op 0 allocs/op
758
- BenchmarkMathFloat64-8 2000000000 0.44 ns/op 0 B/op 0 allocs/op
848
+ BenchmarkMathInt8-8 1000000000 0.309 ns/op 0 B/op 0 allocs/op
849
+ BenchmarkMathInt32-8 1000000000 0.607 ns/op 0 B/op 0 allocs/op
850
+ BenchmarkMathInt64-8 1000000000 0.312 ns/op 0 B/op 0 allocs/op
851
+ BenchmarkMathAtomicInt32-8 219145921 5.40 ns/op 0 B/op 0 allocs/op
852
+ BenchmarkMathAtomicInt64-8 224230356 5.47 ns/op 0 B/op 0 allocs/op
853
+ BenchmarkMathMutexInt-8 79097586 15.1 ns/op 0 B/op 0 allocs/op
854
+ BenchmarkMathFloat32-8 1000000000 0.300 ns/op 0 B/op 0 allocs/op
855
+ BenchmarkMathFloat64-8 1000000000 0.303 ns/op 0 B/op 0 allocs/op
759
856
PASS
760
- ok _/Users/simonwaldherr/git/golang-benchmarks/math 11.767s
857
+ ok _/Users/simonwaldherr/git/golang-benchmarks/math 7.156s
761
858
```
762
859
763
860
### parse
@@ -803,11 +900,11 @@ func BenchmarkParseFloat(b *testing.B) {
803
900
$ go test -bench . -benchmem
804
901
goos: darwin
805
902
goarch: amd64
806
- BenchmarkParseBool-8 300000000 4.06 ns/op 0 B/op 0 allocs/op
807
- BenchmarkParseInt-8 100000000 17.5 ns/op 0 B/op 0 allocs/op
808
- BenchmarkParseFloat-8 10000000 107 ns/op 0 B/op 0 allocs/op
903
+ BenchmarkParseBool-8 322785903 3.62 ns/op 0 B/op 0 allocs/op
904
+ BenchmarkParseInt-8 42614570 27.8 ns/op 0 B/op 0 allocs/op
905
+ BenchmarkParseFloat-8 8117090 143 ns/op 0 B/op 0 allocs/op
809
906
PASS
810
- ok _/Users/simonwaldherr/git/golang-benchmarks/parse 4.713s
907
+ ok _/Users/simonwaldherr/git/golang-benchmarks/parse 4.551s
811
908
```
812
909
813
910
### random
@@ -870,11 +967,11 @@ func GenerateRandomString(s int) (string, error) {
870
967
$ go test -bench . -benchmem
871
968
goos: darwin
872
969
goarch: amd64
873
- BenchmarkMathRand-8 30000000 46.3 ns/op 0 B/op 0 allocs/op
874
- BenchmarkCryptoRand-8 3000000 428 ns/op 162 B/op 5 allocs/op
875
- BenchmarkCryptoRandString-8 5000000 242 ns/op 128 B/op 3 allocs/op
970
+ BenchmarkMathRand-8 39486104 29.7 ns/op 0 B/op 0 allocs/op
971
+ BenchmarkCryptoRand-8 5487919 216 ns/op 56 B/op 4 allocs/op
972
+ BenchmarkCryptoRandString-8 6349160 194 ns/op 128 B/op 3 allocs/op
876
973
PASS
877
- ok _/Users/simonwaldherr/git/golang-benchmarks/random 4.637s
974
+ ok _/Users/simonwaldherr/git/golang-benchmarks/random 4.614s
878
975
```
879
976
880
977
### regexp
@@ -928,10 +1025,10 @@ func BenchmarkMatchStringGolibs(b *testing.B) {
928
1025
$ go test -bench . -benchmem
929
1026
goos: darwin
930
1027
goarch: amd64
931
- BenchmarkMatchString-8 100000 18692 ns/op 48224 B/op 96 allocs/op
932
- BenchmarkMatchStringCompiled-8 2000000 840 ns/op 0 B/op 0 allocs/op
933
- BenchmarkMatchStringGolibs-8 2000000 773 ns/op 0 B/op 0 allocs/op
1028
+ BenchmarkMatchString-8 108385 11555 ns/op 9944 B/op 86 allocs/op
1029
+ BenchmarkMatchStringCompiled-8 2014852 636 ns/op 0 B/op 0 allocs/op
1030
+ BenchmarkMatchStringGolibs-8 1863304 589 ns/op 0 B/op 0 allocs/op
934
1031
PASS
935
- ok _/Users/simonwaldherr/git/golang-benchmarks/regexp 6.852s
1032
+ ok _/Users/simonwaldherr/git/golang-benchmarks/regexp 5.698s
936
1033
```
937
1034
0 commit comments