-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba8aac5
commit b35a487
Showing
6 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
build: | ||
go test -c -o base64-bench.exec | ||
|
||
bench: | ||
time ./base64-bench.exec -test.v -test.benchmem -test.bench ^Benchmark -test.count 5 -test.run ^$ > bench.txt | ||
|
||
run: build bench |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# base64 | ||
|
||
## Who | ||
|
||
``` | ||
github.com/cristalhq/base64 v0.1.2 | ||
github.com/segmentio/asm v1.1.4 | ||
``` | ||
|
||
## Where | ||
|
||
``` | ||
MacBook Pro (16-inch, 2019) | ||
2,6 GHz 6-Core Intel Core i7 | ||
16 GB 2667 MHz DDR4 | ||
``` | ||
|
||
## How | ||
|
||
```shell script | ||
# build & run benchmark | ||
$ make run | ||
|
||
# or in steps | ||
|
||
# build test executable | ||
$ go test -c -o base64-bench.exec | ||
|
||
# run executable | ||
$ time ./base64-bench.exec -v -benchmem -bench ^Benchmark -count 5 -run ^$ > bench.txt | ||
``` | ||
|
||
## Results | ||
|
||
See [bench.txt](https://github.com/cristalhq/benchmarks/blob/main/base64/bench.txt) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
goos: darwin | ||
goarch: arm64 | ||
pkg: github.com/cristaloleg/benches/base64 | ||
Benchmark_cristalhq | ||
Benchmark_cristalhq-10 586058 2063 ns/op 3970.22 MB/s 12288 B/op 1 allocs/op | ||
Benchmark_cristalhq-10 591297 2212 ns/op 3703.11 MB/s 12288 B/op 1 allocs/op | ||
Benchmark_cristalhq-10 534670 2254 ns/op 3633.67 MB/s 12288 B/op 1 allocs/op | ||
Benchmark_cristalhq-10 544071 2248 ns/op 3644.62 MB/s 12288 B/op 1 allocs/op | ||
Benchmark_cristalhq-10 534746 2093 ns/op 3913.14 MB/s 12288 B/op 1 allocs/op | ||
Benchmark_golang | ||
Benchmark_golang-10 203595 5799 ns/op 1412.60 MB/s 24576 B/op 2 allocs/op | ||
Benchmark_golang-10 206269 5834 ns/op 1404.17 MB/s 24576 B/op 2 allocs/op | ||
Benchmark_golang-10 205230 5795 ns/op 1413.72 MB/s 24576 B/op 2 allocs/op | ||
Benchmark_golang-10 207208 5828 ns/op 1405.53 MB/s 24576 B/op 2 allocs/op | ||
Benchmark_golang-10 204903 5803 ns/op 1411.58 MB/s 24576 B/op 2 allocs/op | ||
Benchmark_segmentio | ||
Benchmark_segmentio-10 590043 1958 ns/op 4184.40 MB/s 24576 B/op 2 allocs/op | ||
Benchmark_segmentio-10 617035 1956 ns/op 4187.37 MB/s 24576 B/op 2 allocs/op | ||
Benchmark_segmentio-10 610040 1945 ns/op 4211.46 MB/s 24576 B/op 2 allocs/op | ||
Benchmark_segmentio-10 607477 1950 ns/op 4201.10 MB/s 24576 B/op 2 allocs/op | ||
Benchmark_segmentio-10 618952 1972 ns/op 4153.74 MB/s 24576 B/op 2 allocs/op | ||
PASS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package base64_test | ||
|
||
import ( | ||
"math/rand" | ||
"testing" | ||
|
||
golang "encoding/base64" | ||
|
||
cristalhq "github.com/cristalhq/base64" | ||
segmentio "github.com/segmentio/asm/base64" | ||
) | ||
|
||
func Benchmark_cristalhq(b *testing.B) { | ||
data := make([]byte, 8192) | ||
b.SetBytes(int64(len(data))) | ||
b.ReportAllocs() | ||
b.ResetTimer() | ||
|
||
var v int64 | ||
for i := 0; i < b.N; i++ { | ||
res := cristalhq.StdEncoding.EncodeToString(data) | ||
v += int64(len(res)) | ||
} | ||
|
||
sinkValue(v) | ||
} | ||
|
||
func Benchmark_golang(b *testing.B) { | ||
data := make([]byte, 8192) | ||
b.SetBytes(int64(len(data))) | ||
b.ReportAllocs() | ||
b.ResetTimer() | ||
|
||
var v int64 | ||
for i := 0; i < b.N; i++ { | ||
res := golang.StdEncoding.EncodeToString(data) | ||
v += int64(len(res)) | ||
} | ||
|
||
sinkValue(v) | ||
} | ||
|
||
func Benchmark_segmentio(b *testing.B) { | ||
data := make([]byte, 8192) | ||
b.SetBytes(int64(len(data))) | ||
b.ReportAllocs() | ||
b.ResetTimer() | ||
|
||
var v int64 | ||
|
||
for i := 0; i < b.N; i++ { | ||
res := segmentio.StdEncoding.EncodeToString(data) | ||
v += int64(len(res)) | ||
} | ||
|
||
sinkValue(v) | ||
} | ||
|
||
func checkErr(tb testing.TB, err error) { | ||
if err != nil { | ||
tb.Fatal(err) | ||
} | ||
} | ||
|
||
func sinkValue(v int64) { | ||
if rand.Float64() > 2 { | ||
panic(v) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module github.com/cristaloleg/benches/base64 | ||
|
||
go 1.17 | ||
|
||
require ( | ||
github.com/cristalhq/base64 v0.1.2 | ||
github.com/segmentio/asm v1.1.4 | ||
) | ||
|
||
require golang.org/x/sys v0.0.0-20211110154304-99a53858aa08 // indirect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
github.com/cristalhq/base64 v0.1.2 h1:edsefYyYDiac7Ytdh2xdaiiSSJzcI2f0yIkdGEf1qY0= | ||
github.com/cristalhq/base64 v0.1.2/go.mod h1:sy4+2Hale2KbtSqkzpdMeYTP/IrB+HCvxVHWsh2VSYk= | ||
github.com/segmentio/asm v1.1.4 h1:Q/FKBtrgnmDc0YMrurLROqG9mXE6Ndn276EtDnoWtMM= | ||
github.com/segmentio/asm v1.1.4/go.mod h1:Ld3L4ZXGNcSLRg4JBsZ3//1+f/TjYl0Mzen/DQy1EJg= | ||
golang.org/x/sys v0.0.0-20211110154304-99a53858aa08 h1:WecRHqgE09JBkh/584XIE6PMz5KKE/vER4izNUi30AQ= | ||
golang.org/x/sys v0.0.0-20211110154304-99a53858aa08/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= |