mirror of
https://github.com/golang/go
synced 2024-11-22 06:34:40 -07:00
gob: add UpdateMemStats calls to malloc counter
R=golang-dev, dsymonds CC=golang-dev https://golang.org/cl/4808071
This commit is contained in:
parent
ee9168d507
commit
19e80b0818
@ -484,7 +484,7 @@ func isZero(val reflect.Value) bool {
|
|||||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
|
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
|
||||||
return val.Uint() == 0
|
return val.Uint() == 0
|
||||||
}
|
}
|
||||||
panic("unknown type in isZero" + val.Type().String())
|
panic("unknown type in isZero " + val.Type().String())
|
||||||
}
|
}
|
||||||
|
|
||||||
// encGobEncoder encodes a value that implements the GobEncoder interface.
|
// encGobEncoder encodes a value that implements the GobEncoder interface.
|
||||||
|
@ -53,6 +53,7 @@ func TestCountEncodeMallocs(t *testing.T) {
|
|||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
enc := NewEncoder(&buf)
|
enc := NewEncoder(&buf)
|
||||||
bench := &Bench{7, 3.2, "now is the time", []byte("for all good men")}
|
bench := &Bench{7, 3.2, "now is the time", []byte("for all good men")}
|
||||||
|
runtime.UpdateMemStats()
|
||||||
mallocs := 0 - runtime.MemStats.Mallocs
|
mallocs := 0 - runtime.MemStats.Mallocs
|
||||||
const count = 1000
|
const count = 1000
|
||||||
for i := 0; i < count; i++ {
|
for i := 0; i < count; i++ {
|
||||||
@ -61,6 +62,7 @@ func TestCountEncodeMallocs(t *testing.T) {
|
|||||||
t.Fatal("encode:", err)
|
t.Fatal("encode:", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
runtime.UpdateMemStats()
|
||||||
mallocs += runtime.MemStats.Mallocs
|
mallocs += runtime.MemStats.Mallocs
|
||||||
fmt.Printf("mallocs per encode of type Bench: %d\n", mallocs/count)
|
fmt.Printf("mallocs per encode of type Bench: %d\n", mallocs/count)
|
||||||
}
|
}
|
||||||
@ -77,6 +79,7 @@ func TestCountDecodeMallocs(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
dec := NewDecoder(&buf)
|
dec := NewDecoder(&buf)
|
||||||
|
runtime.UpdateMemStats()
|
||||||
mallocs := 0 - runtime.MemStats.Mallocs
|
mallocs := 0 - runtime.MemStats.Mallocs
|
||||||
for i := 0; i < count; i++ {
|
for i := 0; i < count; i++ {
|
||||||
*bench = Bench{}
|
*bench = Bench{}
|
||||||
@ -85,6 +88,7 @@ func TestCountDecodeMallocs(t *testing.T) {
|
|||||||
t.Fatal("decode:", err)
|
t.Fatal("decode:", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
runtime.UpdateMemStats()
|
||||||
mallocs += runtime.MemStats.Mallocs
|
mallocs += runtime.MemStats.Mallocs
|
||||||
fmt.Printf("mallocs per decode of type Bench: %d\n", mallocs/count)
|
fmt.Printf("mallocs per decode of type Bench: %d\n", mallocs/count)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user