-
Notifications
You must be signed in to change notification settings - Fork 5
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
d59a522
commit 6933d9c
Showing
16 changed files
with
560 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,9 @@ | ||
#!/bin/bash | ||
set -x | ||
|
||
for f in maplookup_test.go equal_test.go; do | ||
go test -bench . -benchmem $f > ${f%_test.go}.txt | ||
done | ||
|
||
./bench_zerocopy.sh | ||
./bench_strconv.sh |
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,9 @@ | ||
#!/bin/bash | ||
set -x | ||
|
||
echo '// go1.22' > strconv.txt | ||
go test -gcflags='-m' -bench . -benchmem ./strconv_test.go \ | ||
1>>strconv.txt 2>strconv122.log | ||
echo '// go1.19' >> strconv.txt | ||
go1.19 test -gcflags='-m' -bench . -benchmem ./strconv_test.go \ | ||
1>>strconv.txt 2>strconv119.log |
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 @@ | ||
echo '// zerocopy=1' > zerocopy.txt | ||
go test -gcflags='-d zerocopy=1 -m' -bench . -benchmem ./zerocopy_test.go \ | ||
1>>zerocopy.txt 2>zerocopy1.log | ||
echo '// zerocopy=0' >> zerocopy.txt | ||
go test -gcflags='-d zerocopy=0 -m' -bench . -benchmem ./zerocopy_test.go \ | ||
1>>zerocopy.txt 2>zerocopy0.log |
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,9 @@ | ||
goos: linux | ||
goarch: amd64 | ||
cpu: 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz | ||
BenchmarkEqual/Optimized-8 1000000000 0.2547 ns/op 0 B/op 0 allocs/op | ||
BenchmarkEqual/NotOptimized-8 26003533 46.33 ns/op 160 B/op 2 allocs/op | ||
BenchmarkEqual/Optimized2-8 382775796 3.174 ns/op 0 B/op 0 allocs/op | ||
BenchmarkEqual/bytes.Equal-8 1000000000 0.2310 ns/op 0 B/op 0 allocs/op | ||
PASS | ||
ok command-line-arguments 3.328s |
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,34 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
) | ||
|
||
func BenchmarkEqual(b *testing.B) { | ||
bs1 := []byte("a looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong string") | ||
bs2 := []byte("a looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong string2") | ||
|
||
b.Run("Optimized", func(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
_ = string(bs1) == string(bs2) | ||
} | ||
}) | ||
b.Run("NotOptimized", func(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
s1 := string(bs1) | ||
s2 := string(bs2) | ||
_ = s1 == s2 | ||
} | ||
}) | ||
b.Run("Optimized2", func(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
_ = string(bs1) >= string(bs2) | ||
} | ||
}) | ||
b.Run("bytes.Equal", func(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
_ = bytes.Equal(bs1, bs2) | ||
} | ||
}) | ||
} |
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 @@ | ||
goos: linux | ||
goarch: amd64 | ||
cpu: 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz | ||
BenchmarkMapLookup/Optimized-8 222915559 5.483 ns/op 0 B/op 0 allocs/op | ||
BenchmarkMapLookup/NotOptimized-8 49391640 33.78 ns/op 48 B/op 1 allocs/op | ||
PASS | ||
ok command-line-arguments 3.465s |
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,24 @@ | ||
package main | ||
|
||
import "testing" | ||
|
||
func BenchmarkMapLookup(b *testing.B) { | ||
m := map[string]string{ | ||
"foo": "foo", | ||
"bar": "bar", | ||
"a log string": "a log string", | ||
"another log string": "another log string", | ||
} | ||
var k = []byte("a looooooooooooooooooooong string") | ||
b.Run("Optimized", func(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
_ = m[string(k)] | ||
} | ||
}) | ||
b.Run("NotOptimized", func(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
sk := string(k) | ||
_ = m[sk] | ||
} | ||
}) | ||
} |
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,14 @@ | ||
// go1.22 | ||
goos: linux | ||
goarch: amd64 | ||
cpu: 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz | ||
BenchmarkStrconv-8 86147509 12.70 ns/op 0 B/op 0 allocs/op | ||
PASS | ||
ok command-line-arguments 1.111s | ||
// go1.19 | ||
goos: linux | ||
goarch: amd64 | ||
cpu: 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz | ||
BenchmarkStrconv-8 51321450 21.73 ns/op 8 B/op 1 allocs/op | ||
PASS | ||
ok command-line-arguments 1.142s |
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,9 @@ | ||
# command-line-arguments [command-line-arguments.test] | ||
./strconv_test.go:8:23: b does not escape | ||
./strconv_test.go:9:13: []byte{...} does not escape | ||
./strconv_test.go:11:33: string(s) escapes to heap | ||
# command-line-arguments.test | ||
_testmain.go:37:6: can inline init.0 | ||
_testmain.go:45:24: inlining call to testing.MainStart | ||
_testmain.go:45:42: testdeps.TestDeps{} escapes to heap | ||
_testmain.go:45:24: &testing.M{...} escapes to heap |
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,9 @@ | ||
# command-line-arguments [command-line-arguments.test] | ||
./strconv_test.go:8:23: b does not escape | ||
./strconv_test.go:9:13: []byte{...} does not escape | ||
./strconv_test.go:11:34: string(s) does not escape | ||
# command-line-arguments.test | ||
_testmain.go:37:6: can inline init.0 | ||
_testmain.go:45:24: inlining call to testing.MainStart | ||
_testmain.go:45:42: testdeps.TestDeps{} escapes to heap | ||
_testmain.go:45:24: &testing.M{...} escapes to heap |
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,13 @@ | ||
package main | ||
|
||
import ( | ||
"strconv" | ||
"testing" | ||
) | ||
|
||
func BenchmarkStrconv(b *testing.B) { | ||
s := []byte{50, 48, 50, 52, 48, 53} | ||
for i := 0; i < b.N; i++ { | ||
_, _ = strconv.ParseInt(string(s), 10, 0) | ||
} | ||
} |
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,14 @@ | ||
// zerocopy=1 | ||
goos: linux | ||
goarch: amd64 | ||
cpu: 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz | ||
BenchmarkZeroCopy-8 1000000000 0.2157 ns/op 0 B/op 0 allocs/op | ||
PASS | ||
ok command-line-arguments 0.241s | ||
// zerocopy=0 | ||
goos: linux | ||
goarch: amd64 | ||
cpu: 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz | ||
BenchmarkZeroCopy-8 418946652 3.056 ns/op 0 B/op 0 allocs/op | ||
PASS | ||
ok command-line-arguments 1.573s |
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,9 @@ | ||
# command-line-arguments [command-line-arguments.test] | ||
./zerocopy_test.go:7:6: can inline BenchmarkZeroCopy | ||
./zerocopy_test.go:7:24: b does not escape | ||
./zerocopy_test.go:10:14: ([]byte)(s) does not escape | ||
# command-line-arguments.test | ||
_testmain.go:37:6: can inline init.0 | ||
_testmain.go:45:24: inlining call to testing.MainStart | ||
_testmain.go:45:42: testdeps.TestDeps{} escapes to heap | ||
_testmain.go:45:24: &testing.M{...} escapes to heap |
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 @@ | ||
# command-line-arguments [command-line-arguments.test] | ||
./zerocopy_test.go:7:6: can inline BenchmarkZeroCopy | ||
./zerocopy_test.go:7:24: b does not escape | ||
./zerocopy_test.go:10:14: ([]byte)(s) does not escape | ||
./zerocopy_test.go:10:14: zero-copy string->[]byte conversion | ||
# command-line-arguments.test | ||
_testmain.go:37:6: can inline init.0 | ||
_testmain.go:45:24: inlining call to testing.MainStart | ||
_testmain.go:45:42: testdeps.TestDeps{} escapes to heap | ||
_testmain.go:45:24: &testing.M{...} escapes to heap |
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,12 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func BenchmarkZeroCopy(b *testing.B) { | ||
s := "202405" | ||
for i := 0; i < b.N; i++ { | ||
_ = []byte(s) | ||
} | ||
} |
Oops, something went wrong.