Skip to content

Commit 0c2d7ec

Browse files
committed
updateBenchLogs.sh and other small changes
1 parent 117a5be commit 0c2d7ec

File tree

4 files changed

+193
-62
lines changed

4 files changed

+193
-62
lines changed

.github/FUNDING.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
github: simonwaldherr
2+
patreon: simonwaldherr
3+
open_collective: # Replace with a single Open Collective username
4+
ko_fi: # Replace with a single Ko-fi username
5+
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
6+
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
7+
liberapay: SimonWaldherr
8+
issuehunt: # Replace with a single IssueHunt username
9+
otechie: # Replace with a single Otechie username
10+
custom: ['https://flattr.com/@SimonWaldherr']

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2019 Simon Waldherr
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+

README.md

Lines changed: 158 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ In order for you to benefit from it too, I will publish such benchmarks in this
1414
* [foreach](https://github.com/SimonWaldherr/golang-benchmarks#foreach)
1515
* [hash](https://github.com/SimonWaldherr/golang-benchmarks#hash)
1616
* [index](https://github.com/SimonWaldherr/golang-benchmarks#index)
17+
* [json](https://github.com/SimonWaldherr/golang-benchmarks#json)
1718
* [math](https://github.com/SimonWaldherr/golang-benchmarks#math)
1819
* [parse](https://github.com/SimonWaldherr/golang-benchmarks#parse)
1920
* [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
3637

3738
## Benchmark Results
3839

40+
Golang Version: go version go1.13.3 darwin/amd64
41+
3942
### base64
4043

4144
```go
@@ -85,10 +88,10 @@ func BenchmarkBase64regex(b *testing.B) {
8588
$ go test -bench . -benchmem
8689
goos: darwin
8790
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
9093
PASS
91-
ok _/Users/simonwaldherr/git/golang-benchmarks/base64 4.188s
94+
ok _/Users/simonwaldherr/git/golang-benchmarks/base64 3.749s
9295
```
9396

9497
### between
@@ -180,12 +183,12 @@ func BenchmarkFulltextParse(b *testing.B) {
180183
$ go test -bench . -benchmem
181184
goos: darwin
182185
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
187190
PASS
188-
ok _/Users/simonwaldherr/git/golang-benchmarks/between 7.470s
191+
ok _/Users/simonwaldherr/git/golang-benchmarks/between 8.005s
189192
```
190193

191194
### concat
@@ -231,11 +234,11 @@ func BenchmarkConcatBuilder(b *testing.B) {
231234
$ go test -bench . -benchmem
232235
goos: darwin
233236
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
237240
PASS
238-
ok _/Users/simonwaldherr/git/golang-benchmarks/concat 62.394s
241+
ok _/Users/simonwaldherr/git/golang-benchmarks/concat 56.321s
239242
```
240243

241244
### contains
@@ -385,16 +388,16 @@ func BenchmarkMatchNot(b *testing.B) {
385388
$ go test -bench . -benchmem
386389
goos: darwin
387390
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
396399
PASS
397-
ok _/Users/simonwaldherr/git/golang-benchmarks/contains 12.979s
400+
ok _/Users/simonwaldherr/git/golang-benchmarks/contains 16.158s
398401
```
399402

400403
### foreach
@@ -481,12 +484,12 @@ func BenchmarkRangeSliceKey(b *testing.B) {
481484
$ go test -bench . -benchmem
482485
goos: darwin
483486
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
488491
PASS
489-
ok _/Users/simonwaldherr/git/golang-benchmarks/foreach 7.654s
492+
ok _/Users/simonwaldherr/git/golang-benchmarks/foreach 6.098s
490493
```
491494

492495
### hash
@@ -568,18 +571,18 @@ func BenchmarkWhirlpool(b *testing.B) {
568571
$ go test -bench . -benchmem
569572
goos: darwin
570573
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
581584
PASS
582-
ok _/Users/simonwaldherr/git/golang-benchmarks/hash 16.537s
585+
ok _/Users/simonwaldherr/git/golang-benchmarks/hash 14.421s
583586
```
584587

585588
### index
@@ -662,10 +665,104 @@ func BenchmarkMapIntKeys(b *testing.B) {
662665
$ go test -bench . -benchmem
663666
goos: darwin
664667
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
667764
PASS
668-
ok _/Users/simonwaldherr/git/golang-benchmarks/index 5.078s
765+
ok _/Users/simonwaldherr/git/golang-benchmarks/json 3.923s
669766
```
670767

671768
### math
@@ -748,16 +845,16 @@ func BenchmarkMathFloat64(b *testing.B) {
748845
$ go test -bench . -benchmem
749846
goos: darwin
750847
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
759856
PASS
760-
ok _/Users/simonwaldherr/git/golang-benchmarks/math 11.767s
857+
ok _/Users/simonwaldherr/git/golang-benchmarks/math 7.156s
761858
```
762859

763860
### parse
@@ -803,11 +900,11 @@ func BenchmarkParseFloat(b *testing.B) {
803900
$ go test -bench . -benchmem
804901
goos: darwin
805902
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
809906
PASS
810-
ok _/Users/simonwaldherr/git/golang-benchmarks/parse 4.713s
907+
ok _/Users/simonwaldherr/git/golang-benchmarks/parse 4.551s
811908
```
812909

813910
### random
@@ -870,11 +967,11 @@ func GenerateRandomString(s int) (string, error) {
870967
$ go test -bench . -benchmem
871968
goos: darwin
872969
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
876973
PASS
877-
ok _/Users/simonwaldherr/git/golang-benchmarks/random 4.637s
974+
ok _/Users/simonwaldherr/git/golang-benchmarks/random 4.614s
878975
```
879976

880977
### regexp
@@ -928,10 +1025,10 @@ func BenchmarkMatchStringGolibs(b *testing.B) {
9281025
$ go test -bench . -benchmem
9291026
goos: darwin
9301027
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
9341031
PASS
935-
ok _/Users/simonwaldherr/git/golang-benchmarks/regexp 6.852s
1032+
ok _/Users/simonwaldherr/git/golang-benchmarks/regexp 5.698s
9361033
```
9371034

updateBenchLogs.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ EOM
4242

4343
go fmt ./...
4444

45-
45+
echo -n "Golang Version: " >> README.md
46+
go version >> README.md
47+
echo "" >> README.md
4648

4749
for i in "${benchs[@]}"
4850
do

0 commit comments

Comments
 (0)