Automated rollback of commit 2e361fb75a

PiperOrigin-RevId: 270757066
This commit is contained in:
A. Unique TensorFlower 2019-09-23 14:10:56 -07:00 committed by TensorFlower Gardener
parent ad1644033a
commit 0f541c0290

View File

@ -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