2021_12
参加者
syumai
magicpro
bnn
Nobishii
読むもの
weekly proposal review meeting
見るやつ
reflect.Value.Grow
reflect.Value.Bytes()
adressableな配列のValueからもBytes()を取りたい!
http.MaxBytesError
(*URL).PathJoin / url.JoinPath
メモ
code:golang
package main
import (
"reflect"
"testing"
)
func BenchmarkByAppend(b *testing.B) {
for i := 0; i < b.N; i++ {
s := make([]int, 0, 5)
v1 := reflect.ValueOf(&s).Elem()
v1 = reflect.Append(v1, reflect.ValueOf(1))
v1 = reflect.Append(v1, reflect.ValueOf(2))
}
}
func BenchmarkByAppend2(b *testing.B) {
for i := 0; i < b.N; i++ {
s := make([]int, 0, 5)
v1 := reflect.ValueOf(&s).Elem()
v1.Set(reflect.Append(v1, reflect.ValueOf(1)))
v1.Set(reflect.Append(v1, reflect.ValueOf(2)))
}
}
func BenchmarkBySet(b *testing.B) {
for i := 0; i < b.N; i++ {
s := make([]int, 0, 5)
v1 := reflect.ValueOf(&s).Elem()
v1.SetLen(2)
v1.Index(0).Set(reflect.ValueOf(1))
v1.Index(1).Set(reflect.ValueOf(2))
}
}
cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
BenchmarkByAppend-16 6878270 172.4 ns/op 120 B/op 4 allocs/op
BenchmarkByAppend2-16 5854520 207.3 ns/op 120 B/op 4 allocs/op
BenchmarkBySet-16 12376485 97.96 ns/op 72 B/op 2 allocs/op
PASS