From 0f541c02904321d3da666cccd3c94a9e99dedf48 Mon Sep 17 00:00:00 2001 From: "A. Unique TensorFlower" <gardener@tensorflow.org> Date: Mon, 23 Sep 2019 14:10:56 -0700 Subject: [PATCH] Automated rollback of commit 2e361fb75a65c351d3b2eee4b99a64bcc689d7a3 PiperOrigin-RevId: 270757066 --- tensorflow/core/framework/tensor_test.cc | 55 ++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/tensorflow/core/framework/tensor_test.cc b/tensorflow/core/framework/tensor_test.cc index 01a0971b152..46582163ee3 100644 --- a/tensorflow/core/framework/tensor_test.cc +++ b/tensorflow/core/framework/tensor_test.cc @@ -17,6 +17,7 @@ limitations under the License. #include "tensorflow/core/framework/tensor.pb.h" #include "tensorflow/core/framework/tensor_testutil.h" +#include "tensorflow/core/framework/tensor_util.h" #include "tensorflow/core/framework/types.h" #include "tensorflow/core/framework/variant.h" #include "tensorflow/core/framework/variant_encode_decode.h" @@ -1518,5 +1519,59 @@ void BM_CreateAndDestroyHostScalarOptimized(int iters) { } BENCHMARK(BM_CreateAndDestroyHostScalarOptimized); +static void BM_FromProto(int iters, int size) { + testing::StopTiming(); + TensorShape shape({size}); + Allocator* allocator = cpu_allocator(); + Tensor a(allocator, DT_FLOAT, shape); + std::fill_n(a.flat<float>().data(), size, 42.0); + TensorProto p; + a.AsProtoField(&p); + testing::StartTiming(); + while (--iters) { + Tensor b; + ASSERT_TRUE(b.FromProto(p)); + } + testing::StopTiming(); +} +BENCHMARK(BM_FromProto)->Range(1, 1 << 20); + +static void BM_FromProtoCompressed(int iters, int size) { + testing::StopTiming(); + TensorShape shape({size}); + Allocator* allocator = cpu_allocator(); + Tensor a(allocator, DT_FLOAT, shape); + std::fill_n(a.flat<float>().data(), size, 42.0f); + TensorProto p; + a.AsProtoField(&p); + tensor::CompressTensorProtoInPlace(&p); + testing::StartTiming(); + while (--iters) { + Tensor b; + ASSERT_TRUE(b.FromProto(p)); + } + testing::StopTiming(); +} +BENCHMARK(BM_FromProtoCompressed)->Range(1, 1 << 20); + +static void BM_FromProtoCompressedZero(int iters, int size) { + testing::StopTiming(); + TensorShape shape({size}); + Allocator* allocator = cpu_allocator(); + Tensor a(allocator, DT_FLOAT, shape); + std::fill_n(a.flat<float>().data(), size, 0); + a.flat<float>()(0) = 1; + TensorProto p; + a.AsProtoField(&p); + tensor::CompressTensorProtoInPlace(&p); + testing::StartTiming(); + while (--iters) { + Tensor b; + ASSERT_TRUE(b.FromProto(p)); + } + testing::StopTiming(); +} +BENCHMARK(BM_FromProtoCompressedZero)->Range(1, 1 << 20); + } // namespace } // namespace tensorflow