message: Extend Go benchmarks
diff: @@ -18,6 +18,7 @@ package tensorflow
  import (
  "bytes"
  + "fmt"
  "io"
  "reflect"
  "testing"
  @@ -276,6 +277,7 @@ func TestReadTensorReadAll(t *testing.T) {
  }
  func benchmarkNewTensor(b *testing.B, v interface{}) {
  + b.ReportAllocs()
  for i := 0; i < b.N; i++ {
  if t, err := NewTensor(v); err != nil || t == nil {
  b.Fatalf("(%v, %v)", t, err)
  @@ -283,32 +285,50 @@ func benchmarkNewTensor(b *testing.B, v interface{}) {
  }
  }
  -func BenchmarkNewTensor(b *testing.B) {
  - var (
  - // Some sample sizes from the Inception image labeling model.
  - // Where input tensors correspond to a 224x224 RGB image
  - // flattened into a vector.
  - vector [224 * 224 * 3]int32
  - )
  - b.Run("[150528]", func(b *testing.B) { benchmarkNewTensor(b, vector) })
  +func benchmarkValueTensor(b *testing.B, v interface{}) {
  + t, err := NewTensor(v)
  + if err != nil {
  + b.Fatalf("(%v, %v)", t, err)
  }
  + b.ReportAllocs()
  + b.ResetTimer()
  -func benchmarkDecodeTensor(b *testing.B, t *Tensor) {
  for i := 0; i < b.N; i++ {
  _ = t.Value()
  }
  }
  -func BenchmarkDecodeTensor(b *testing.B) {
  - var (
  +func BenchmarkTensor(b *testing.B) {
  // Some sample sizes from the Inception image labeling model.
  // Where input tensors correspond to a 224x224 RGB image
  // flattened into a vector.
  - vector [224 * 224 * 3]int32
  - )
  - t, err := NewTensor(vector)
  - if err != nil {
  - b.Fatalf("(%v, %v)", t, err)
  + var vector [224 * 224 * 3]int32
  +
  + l3 := make([][][]float32, 100)
  + l2 := make([][]float32, 100*100)
  + l1 := make([]float32, 100*100*100)
  + for i := range l2 {
  + l2[i] = l1[i*100 : (i+1)*100]
  + }
  + for i := range l3 {
  + l3[i] = l2[i*100 : (i+1)*100]
  }
  - b.Run("[150528]", func(b *testing.B) { benchmarkDecodeTensor(b, t) })
  +
  + tests := []interface{}{
  + vector,
  + l1,
  + l2,
  + l3,
  + }
  + b.Run("New", func(b *testing.B) {
  + for _, test := range tests {
  + b.Run(fmt.Sprintf("%T", test), func(b *testing.B) { benchmarkNewTensor(b, test) })
  + }
  + })
  + b.Run("Value", func(b *testing.B) {
  + for _, test := range tests {
  + b.Run(fmt.Sprintf("%T", test), func(b *testing.B) { benchmarkValueTensor(b, test) })
  + }
  + })
  +
  }
  