Update benchmarks to newer API

PiperOrigin-RevId: 356573157
Change-Id: Idc6a37be704b6b785e394be276311a1b85cd4c44
This commit is contained in:
A. Unique TensorFlower 2021-02-09 13:07:55 -08:00 committed by TensorFlower Gardener
parent b461505cb3
commit 3b0a3b7e8d
12 changed files with 130 additions and 116 deletions

View File

@ -49,14 +49,13 @@ TEST(BlockingCounterTest, TestMultipleThread) {
} // namespace } // namespace
static void BM_BlockingCounter(int iters, int num_threads, static void BM_BlockingCounter(::testing::benchmark::State& state) {
int shards_per_thread) { int num_threads = state.range(0);
testing::StopTiming(); int shards_per_thread = state.range(1);
std::unique_ptr<thread::ThreadPool> thread_pool( std::unique_ptr<thread::ThreadPool> thread_pool(
new thread::ThreadPool(Env::Default(), "test", num_threads)); new thread::ThreadPool(Env::Default(), "test", num_threads));
const int num_shards = num_threads * shards_per_thread; const int num_shards = num_threads * shards_per_thread;
testing::StartTiming(); for (auto s : state) {
for (int i = 0; i < iters; ++i) {
BlockingCounter bc(num_shards); BlockingCounter bc(num_shards);
for (int j = 0; j < num_threads; ++j) { for (int j = 0; j < num_threads; ++j) {
thread_pool->Schedule([&bc, shards_per_thread] { thread_pool->Schedule([&bc, shards_per_thread] {
@ -67,7 +66,6 @@ static void BM_BlockingCounter(int iters, int num_threads,
} }
bc.Wait(); bc.Wait();
} }
testing::StopTiming();
} }
BENCHMARK(BM_BlockingCounter)->RangePair(1, 12, 1, 1000); BENCHMARK(BM_BlockingCounter)->RangePair(1, 12, 1, 1000);

View File

@ -202,10 +202,11 @@ TEST(Status, ErasePayloadRemovesIt) {
ASSERT_EQ(s.GetPayload("Error key"), tensorflow::StringPiece()); ASSERT_EQ(s.GetPayload("Error key"), tensorflow::StringPiece());
} }
static void BM_TF_CHECK_OK(int iters) { static void BM_TF_CHECK_OK(::testing::benchmark::State& state) {
tensorflow::Status s = tensorflow::Status s = (state.max_iterations < 0)
(iters < 0) ? errors::InvalidArgument("Invalid") : Status::OK(); ? errors::InvalidArgument("Invalid")
for (int i = 0; i < iters; i++) { : Status::OK();
for (auto i : state) {
TF_CHECK_OK(s); TF_CHECK_OK(s);
} }
} }

View File

@ -267,46 +267,46 @@ volatile int i;
void Incr(volatile int* ip) { ++*ip; } void Incr(volatile int* ip) { ++*ip; }
void Incr() { Incr(&i); } void Incr() { Incr(&i); }
void BM_Cleanup(int iters) { void BM_Cleanup(::testing::benchmark::State& state) {
while (iters--) { for (auto s : state) {
auto fin = gtl::MakeCleanup([] { Incr(); }); auto fin = gtl::MakeCleanup([] { Incr(); });
} }
} }
BENCHMARK(BM_Cleanup); BENCHMARK(BM_Cleanup);
void BM_AnyCleanup(int iters) { void BM_AnyCleanup(::testing::benchmark::State& state) {
while (iters--) { for (auto s : state) {
AnyCleanup fin = gtl::MakeCleanup([] { Incr(); }); AnyCleanup fin = gtl::MakeCleanup([] { Incr(); });
} }
} }
BENCHMARK(BM_AnyCleanup); BENCHMARK(BM_AnyCleanup);
void BM_AnyCleanupNoFactory(int iters) { void BM_AnyCleanupNoFactory(::testing::benchmark::State& state) {
while (iters--) { for (auto s : state) {
AnyCleanup fin([] { Incr(); }); AnyCleanup fin([] { Incr(); });
} }
} }
BENCHMARK(BM_AnyCleanupNoFactory); BENCHMARK(BM_AnyCleanupNoFactory);
void BM_CleanupBound(int iters) { void BM_CleanupBound(::testing::benchmark::State& state) {
volatile int* ip = &i; volatile int* ip = &i;
while (iters--) { for (auto s : state) {
auto fin = gtl::MakeCleanup([ip] { Incr(ip); }); auto fin = gtl::MakeCleanup([ip] { Incr(ip); });
} }
} }
BENCHMARK(BM_CleanupBound); BENCHMARK(BM_CleanupBound);
void BM_AnyCleanupBound(int iters) { void BM_AnyCleanupBound(::testing::benchmark::State& state) {
volatile int* ip = &i; volatile int* ip = &i;
while (iters--) { for (auto s : state) {
AnyCleanup fin = gtl::MakeCleanup([ip] { Incr(ip); }); AnyCleanup fin = gtl::MakeCleanup([ip] { Incr(ip); });
} }
} }
BENCHMARK(BM_AnyCleanupBound); BENCHMARK(BM_AnyCleanupBound);
void BM_AnyCleanupNoFactoryBound(int iters) { void BM_AnyCleanupNoFactoryBound(::testing::benchmark::State& state) {
volatile int* ip = &i; volatile int* ip = &i;
while (iters--) { for (auto s : state) {
AnyCleanup fin([ip] { Incr(ip); }); AnyCleanup fin([ip] { Incr(ip); });
} }
} }

View File

@ -109,7 +109,8 @@ TEST_F(LevenshteinDistanceTest, Vectors) {
6); 6);
} }
static void BM_EditDistanceHelper(int n, int len, bool completely_different) { static void BM_EditDistanceHelper(::testing::benchmark::State& state, int len,
bool completely_different) {
string a = string a =
"The quick brown fox jumped over the lazy dog and on and on and on" "The quick brown fox jumped over the lazy dog and on and on and on"
" Every good boy deserves fudge. In fact, this is a very long sentence " " Every good boy deserves fudge. In fact, this is a very long sentence "
@ -123,18 +124,18 @@ static void BM_EditDistanceHelper(int n, int len, bool completely_different) {
b[i]++; b[i]++;
} }
} }
while (n-- > 0) { for (auto s : state) {
LevenshteinDistance(gtl::ArraySlice<char>(a.data(), len), LevenshteinDistance(gtl::ArraySlice<char>(a.data(), len),
gtl::ArraySlice<char>(b.data(), len), gtl::ArraySlice<char>(b.data(), len),
std::equal_to<char>()); std::equal_to<char>());
} }
} }
static void BM_EditDistanceSame(int n, int len) { static void BM_EditDistanceSame(::testing::benchmark::State& state) {
BM_EditDistanceHelper(n, len, false); BM_EditDistanceHelper(state, state.range(0), false);
} }
static void BM_EditDistanceDiff(int n, int len) { static void BM_EditDistanceDiff(::testing::benchmark::State& state) {
BM_EditDistanceHelper(n, len, true); BM_EditDistanceHelper(state, state.range(0), true);
} }
BENCHMARK(BM_EditDistanceSame)->Arg(5); BENCHMARK(BM_EditDistanceSame)->Arg(5);

View File

@ -81,13 +81,14 @@ TEST(CRC, ExtendWithCord) {
} }
#endif #endif
static void BM_CRC(int iters, int len) { static void BM_CRC(::testing::benchmark::State& state) {
int len = state.range(0);
std::string input(len, 'x'); std::string input(len, 'x');
uint32 h = 0; uint32 h = 0;
for (int i = 0; i < iters; i++) { for (auto s : state) {
h = Extend(h, input.data() + 1, len - 1); h = Extend(h, input.data() + 1, len - 1);
} }
testing::BytesProcessed(static_cast<int64>(iters) * len); state.SetBytesProcessed(state.iterations() * len);
VLOG(1) << h; VLOG(1) << h;
} }
BENCHMARK(BM_CRC)->Range(1, 256 * 1024); BENCHMARK(BM_CRC)->Range(1, 256 * 1024);

View File

@ -72,13 +72,14 @@ TEST(Hash, HashPtrIsNotIdentityFunction) {
EXPECT_NE(hash<int*>()(ptr), size_t{0xcafe0000}); EXPECT_NE(hash<int*>()(ptr), size_t{0xcafe0000});
} }
static void BM_Hash32(int iters, int len) { static void BM_Hash32(::testing::benchmark::State& state) {
int len = state.range(0);
std::string input(len, 'x'); std::string input(len, 'x');
uint32 h = 0; uint32 h = 0;
for (int i = 0; i < iters; i++) { for (auto s : state) {
h = Hash32(input.data(), len, 1); h = Hash32(input.data(), len, 1);
} }
testing::BytesProcessed(static_cast<int64>(iters) * len); state.SetBytesProcessed(state.iterations() * len);
VLOG(1) << h; VLOG(1) << h;
} }
BENCHMARK(BM_Hash32)->Range(1, 1024); BENCHMARK(BM_Hash32)->Range(1, 1024);

View File

@ -82,8 +82,8 @@ TEST_F(DistributionSamplerTest, KnownDistribution) {
TestDistribution(kDist1, TF_ARRAYSIZE(kDist1)); TestDistribution(kDist1, TF_ARRAYSIZE(kDist1));
} }
static void BM_DistributionSampler(int iters, int n) { static void BM_DistributionSampler(::testing::benchmark::State& state) {
testing::StopTiming(); const int n = state.range(0);
PhiloxRandom philox(173, 371); PhiloxRandom philox(173, 371);
SimplePhilox rand(&philox); SimplePhilox rand(&philox);
std::vector<float> weights(n, 0); std::vector<float> weights(n, 0);
@ -91,9 +91,8 @@ static void BM_DistributionSampler(int iters, int n) {
weights[i] = rand.Uniform(100); weights[i] = rand.Uniform(100);
} }
DistributionSampler picker(weights); DistributionSampler picker(weights);
testing::StartTiming();
int r = 0; int r = 0;
for (int i = 0; i < iters; i++) { for (auto s : state) {
r |= picker.Sample(&rand); r |= picker.Sample(&rand);
} }
CHECK_NE(r, kint32max); CHECK_NE(r, kint32max);

View File

@ -234,31 +234,34 @@ static void TestPickAt(int items, const int32* weights) {
EXPECT_EQ(weight_index, picker.total_weight()); EXPECT_EQ(weight_index, picker.total_weight());
} }
static void BM_Create(int iters, int arg) { static void BM_Create(::testing::benchmark::State& state) {
while (--iters > 0) { int arg = state.range(0);
for (auto s : state) {
WeightedPicker p(arg); WeightedPicker p(arg);
} }
} }
BENCHMARK(BM_Create)->Range(1, 1024); BENCHMARK(BM_Create)->Range(1, 1024);
static void BM_CreateAndSetWeights(int iters, int arg) { static void BM_CreateAndSetWeights(::testing::benchmark::State& state) {
int arg = state.range(0);
std::vector<int32> weights(arg); std::vector<int32> weights(arg);
for (int i = 0; i < arg; i++) { for (int i = 0; i < arg; i++) {
weights[i] = i * 10; weights[i] = i * 10;
} }
while (--iters > 0) { for (auto s : state) {
WeightedPicker p(arg); WeightedPicker p(arg);
p.SetWeightsFromArray(arg, &weights[0]); p.SetWeightsFromArray(arg, &weights[0]);
} }
} }
BENCHMARK(BM_CreateAndSetWeights)->Range(1, 1024); BENCHMARK(BM_CreateAndSetWeights)->Range(1, 1024);
static void BM_Pick(int iters, int arg) { static void BM_Pick(::testing::benchmark::State& state) {
int arg = state.range(0);
PhiloxRandom philox(301, 17); PhiloxRandom philox(301, 17);
SimplePhilox rnd(&philox); SimplePhilox rnd(&philox);
WeightedPicker p(arg); WeightedPicker p(arg);
int result = 0; int result = 0;
while (--iters > 0) { for (auto s : state) {
result += p.Pick(&rnd); result += p.Pick(&rnd);
} }
VLOG(4) << result; // Dummy use VLOG(4) << result; // Dummy use

View File

@ -376,18 +376,18 @@ uint64 NextBits(random::SimplePhilox* rnd, int bits) {
} }
template <typename T> template <typename T>
void BM_WriteNum(int n, T multiplier) { void BM_WriteNum(::testing::benchmark::State& state, T multiplier) {
constexpr int kValues = 64; constexpr int kValues = 64;
T values[kValues]; T values[kValues];
random::PhiloxRandom philox(301, 17); random::PhiloxRandom philox(301, 17);
random::SimplePhilox rnd(&philox); random::SimplePhilox rnd(&philox);
// Use enough distinct values to confuse the branch predictor // Use enough distinct values to confuse the branch predictor
for (int i = 0; i < kValues; i++) { for (int i = 0; i < kValues; i++) {
values[i] = NextBits(&rnd, n % 64) * multiplier; values[i] = NextBits(&rnd, state.max_iterations % 64) * multiplier;
} }
string result; string result;
int index = 0; int index = 0;
while (n-- > 0) { for (auto i : state) {
result.clear(); result.clear();
OCWriteToString<T>(&result, values[index % kValues]); OCWriteToString<T>(&result, values[index % kValues]);
index++; index++;
@ -395,7 +395,7 @@ void BM_WriteNum(int n, T multiplier) {
} }
template <typename T> template <typename T>
void BM_ReadNum(int n, T multiplier) { void BM_ReadNum(::testing::benchmark::State& state, T multiplier) {
random::PhiloxRandom philox(301, 17); random::PhiloxRandom philox(301, 17);
random::SimplePhilox rnd(&philox); random::SimplePhilox rnd(&philox);
// Use enough distinct values to confuse the branch predictor // Use enough distinct values to confuse the branch predictor
@ -406,17 +406,21 @@ void BM_ReadNum(int n, T multiplier) {
values[i] = OCWrite<T>(val); values[i] = OCWrite<T>(val);
} }
uint32 index = 0; uint32 index = 0;
while (n-- > 0) { for (auto i : state) {
T val; T val;
StringPiece s = values[index++ % kValues]; StringPiece s = values[index++ % kValues];
OCRead<T>(&s, &val); OCRead<T>(&s, &val);
} }
} }
#define BENCHMARK_NUM(name, T, multiplier) \ #define BENCHMARK_NUM(name, T, multiplier) \
void BM_Write##name(int n) { BM_WriteNum<T>(n, multiplier); } \ void BM_Write##name(::testing::benchmark::State& state) { \
BENCHMARK(BM_Write##name); \ BM_WriteNum<T>(state, multiplier); \
void BM_Read##name(int n) { BM_ReadNum<T>(n, multiplier); } \ } \
BENCHMARK(BM_Write##name); \
void BM_Read##name(::testing::benchmark::State& state) { \
BM_ReadNum<T>(state, multiplier); \
} \
BENCHMARK(BM_Read##name) BENCHMARK(BM_Read##name)
BENCHMARK_NUM(NumIncreasing, uint64, 1); BENCHMARK_NUM(NumIncreasing, uint64, 1);
@ -1209,8 +1213,7 @@ TEST(EncodingIsExpected, Signed) {
} }
} }
void BM_WriteString(int n, int len) { void BM_WriteString(::testing::benchmark::State& state, int len) {
testing::StopTiming();
random::PhiloxRandom philox(301, 17); random::PhiloxRandom philox(301, 17);
random::SimplePhilox rnd(&philox); random::SimplePhilox rnd(&philox);
string x; string x;
@ -1219,16 +1222,14 @@ void BM_WriteString(int n, int len) {
} }
string y; string y;
testing::BytesProcessed(n * len); for (auto s : state) {
testing::StartTiming();
while (n-- > 0) {
y.clear(); y.clear();
OCWriteToString<string>(&y, x); OCWriteToString<string>(&y, x);
} }
state.SetBytesProcessed(state.iterations() * len);
} }
void BM_ReadString(int n, int len) { void BM_ReadString(::testing::benchmark::State& state, int len) {
testing::StopTiming();
random::PhiloxRandom philox(301, 17); random::PhiloxRandom philox(301, 17);
random::SimplePhilox rnd(&philox); random::SimplePhilox rnd(&philox);
string x; string x;
@ -1239,17 +1240,20 @@ void BM_ReadString(int n, int len) {
OCWriteToString<string>(&data, x); OCWriteToString<string>(&data, x);
string result; string result;
testing::BytesProcessed(n * len); for (auto i : state) {
testing::StartTiming();
while (n-- > 0) {
result.clear(); result.clear();
StringPiece s = data; StringPiece s = data;
OCRead<string>(&s, &result); OCRead<string>(&s, &result);
} }
state.SetBytesProcessed(state.iterations() * len);
} }
void BM_WriteStringIncreasing(int n, int len) { BM_WriteString(n, len); } void BM_WriteStringIncreasing(::testing::benchmark::State& state) {
void BM_ReadStringIncreasing(int n, int len) { BM_ReadString(n, len); } BM_WriteString(state, state.range(0));
}
void BM_ReadStringIncreasing(::testing::benchmark::State& state) {
BM_ReadString(state, state.range(0));
}
BENCHMARK(BM_WriteStringIncreasing)->Range(0, 1024); BENCHMARK(BM_WriteStringIncreasing)->Range(0, 1024);
BENCHMARK(BM_ReadStringIncreasing)->Range(0, 1024); BENCHMARK(BM_ReadStringIncreasing)->Range(0, 1024);

View File

@ -16,6 +16,7 @@ limitations under the License.
#include "tensorflow/core/lib/strings/proto_serialization.h" #include "tensorflow/core/lib/strings/proto_serialization.h"
#include <string> #include <string>
#include "absl/memory/memory.h" #include "absl/memory/memory.h"
#include "tensorflow/core/framework/attr_value.pb.h" #include "tensorflow/core/framework/attr_value.pb.h"
#include "tensorflow/core/framework/graph.pb.h" #include "tensorflow/core/framework/graph.pb.h"
@ -40,54 +41,55 @@ GraphDef MakeGraphDef(int num_nodes) {
} }
} // namespace } // namespace
static void BM_ProtoSerializationToString(int iters, int num_nodes) { static void BM_ProtoSerializationToString(::testing::benchmark::State& state) {
testing::StopTiming(); int num_nodes = state.range(0);
GraphDef graph_def = MakeGraphDef(num_nodes); GraphDef graph_def = MakeGraphDef(num_nodes);
testing::StartTiming();
for (int i = 0; i < iters; ++i) { for (auto i : state) {
string serialized; string serialized;
testing::DoNotOptimize( testing::DoNotOptimize(
SerializeToStringDeterministic(graph_def, &serialized)); SerializeToStringDeterministic(graph_def, &serialized));
} }
testing::StopTiming();
} }
BENCHMARK(BM_ProtoSerializationToString)->Range(1, 10000); BENCHMARK(BM_ProtoSerializationToString)->Range(1, 10000);
static void BM_ProtoSerializationToBuffer(int iters, int num_nodes) { static void BM_ProtoSerializationToBuffer(::testing::benchmark::State& state) {
testing::StopTiming(); int num_nodes = state.range(0);
GraphDef graph_def = MakeGraphDef(num_nodes); GraphDef graph_def = MakeGraphDef(num_nodes);
testing::StartTiming();
const size_t size = graph_def.ByteSizeLong(); const size_t size = graph_def.ByteSizeLong();
for (int i = 0; i < iters; ++i) { for (auto i : state) {
gtl::InlinedVector<char, 1024> buf(size); gtl::InlinedVector<char, 1024> buf(size);
testing::DoNotOptimize( testing::DoNotOptimize(
SerializeToBufferDeterministic(graph_def, buf.data(), size)); SerializeToBufferDeterministic(graph_def, buf.data(), size));
} }
testing::StopTiming();
} }
BENCHMARK(BM_ProtoSerializationToBuffer)->Range(1, 10000); BENCHMARK(BM_ProtoSerializationToBuffer)->Range(1, 10000);
static void BM_DeterministicProtoHash64(int iters, int num_nodes) { static void BM_DeterministicProtoHash64(::testing::benchmark::State& state) {
testing::StopTiming(); int num_nodes = state.range(0);
GraphDef graph_def = MakeGraphDef(num_nodes); GraphDef graph_def = MakeGraphDef(num_nodes);
testing::StartTiming();
for (int i = 0; i < iters; ++i) { for (auto i : state) {
testing::DoNotOptimize(DeterministicProtoHash64(graph_def)); testing::DoNotOptimize(DeterministicProtoHash64(graph_def));
} }
testing::StopTiming();
} }
BENCHMARK(BM_DeterministicProtoHash64)->Range(1, 10000); BENCHMARK(BM_DeterministicProtoHash64)->Range(1, 10000);
static void BM_AreSerializedProtosEqual(int iters, int num_nodes) { static void BM_AreSerializedProtosEqual(::testing::benchmark::State& state) {
testing::StopTiming(); int num_nodes = state.range(0);
GraphDef graph_def_a = MakeGraphDef(num_nodes); GraphDef graph_def_a = MakeGraphDef(num_nodes);
GraphDef graph_def_b = MakeGraphDef(num_nodes); GraphDef graph_def_b = MakeGraphDef(num_nodes);
graph_def_b.mutable_node(0)->mutable_name()[0] = 'l'; graph_def_b.mutable_node(0)->mutable_name()[0] = 'l';
testing::StartTiming();
for (int i = 0; i < iters; ++i) { for (auto i : state) {
testing::DoNotOptimize(AreSerializedProtosEqual(graph_def_a, graph_def_a)); testing::DoNotOptimize(AreSerializedProtosEqual(graph_def_a, graph_def_a));
} }
testing::StopTiming();
} }
BENCHMARK(BM_AreSerializedProtosEqual)->Range(1, 10000); BENCHMARK(BM_AreSerializedProtosEqual)->Range(1, 10000);

View File

@ -744,7 +744,9 @@ TEST(SparseTensorTest, Dim0SparseTensorToDenseTensor) {
EXPECT_EQ(dense.scalar<int32>()(), 5); EXPECT_EQ(dense.scalar<int32>()(), 5);
} }
static void BM_SparseReorderFloat(int iters, int N32, int NDIM32) { static void BM_SparseReorderFloat(::testing::benchmark::State& state) {
int N32 = state.range(0);
int NDIM32 = state.range(1);
random::PhiloxRandom philox(301, 17); random::PhiloxRandom philox(301, 17);
random::SimplePhilox rnd(&philox); random::SimplePhilox rnd(&philox);
const int64 NDIM = static_cast<int64>(NDIM32); const int64 NDIM = static_cast<int64>(NDIM32);
@ -764,10 +766,9 @@ static void BM_SparseReorderFloat(int iters, int N32, int NDIM32) {
reorder.push_back(d); reorder.push_back(d);
} }
auto ix_t = ix.matrix<int64>(); auto ix_t = ix.matrix<int64>();
testing::UseRealTime();
while (--iters) { for (auto s : state) {
testing::StopTiming(); state.PauseTiming();
for (int64 i = 0; i < N; ++i) { for (int64 i = 0; i < N; ++i) {
for (int d = 0; d < NDIM32; ++d) { for (int d = 0; d < NDIM32; ++d) {
ix_t(i, d) = rnd.Rand64() % 1000; ix_t(i, d) = rnd.Rand64() % 1000;
@ -776,12 +777,14 @@ static void BM_SparseReorderFloat(int iters, int N32, int NDIM32) {
SparseTensor st; SparseTensor st;
TF_ASSERT_OK(SparseTensor::Create(ix, vals, shape, order, &st)); TF_ASSERT_OK(SparseTensor::Create(ix, vals, shape, order, &st));
testing::StartTiming(); state.ResumeTiming();
st.Reorder<float>(reorder); st.Reorder<float>(reorder);
} }
} }
static void BM_SparseReorderString(int iters, int N32, int NDIM32) { static void BM_SparseReorderString(::testing::benchmark::State& state) {
int N32 = state.range(0);
int NDIM32 = state.range(1);
random::PhiloxRandom philox(301, 17); random::PhiloxRandom philox(301, 17);
random::SimplePhilox rnd(&philox); random::SimplePhilox rnd(&philox);
const int64 NDIM = static_cast<int64>(NDIM32); const int64 NDIM = static_cast<int64>(NDIM32);
@ -806,10 +809,9 @@ static void BM_SparseReorderString(int iters, int N32, int NDIM32) {
for (int d = 2; d < NDIM32; ++d) { for (int d = 2; d < NDIM32; ++d) {
reorder.push_back(d); reorder.push_back(d);
} }
testing::UseRealTime();
while (--iters) { for (auto s : state) {
testing::StopTiming(); state.PauseTiming();
for (int64 i = 0; i < N; ++i) { for (int64 i = 0; i < N; ++i) {
for (int d = 0; d < NDIM32; ++d) { for (int d = 0; d < NDIM32; ++d) {
ix_t(i, d) = rnd.Rand64() % 1000; ix_t(i, d) = rnd.Rand64() % 1000;
@ -818,30 +820,30 @@ static void BM_SparseReorderString(int iters, int N32, int NDIM32) {
SparseTensor st; SparseTensor st;
TF_ASSERT_OK(SparseTensor::Create(ix, vals, shape, order, &st)); TF_ASSERT_OK(SparseTensor::Create(ix, vals, shape, order, &st));
testing::StartTiming(); state.ResumeTiming();
st.Reorder<tstring>(reorder); st.Reorder<tstring>(reorder);
} }
} }
BENCHMARK(BM_SparseReorderFloat)->ArgPair(10, 2); BENCHMARK(BM_SparseReorderFloat)->UseRealTime()->ArgPair(10, 2);
BENCHMARK(BM_SparseReorderFloat)->ArgPair(100, 2); BENCHMARK(BM_SparseReorderFloat)->UseRealTime()->ArgPair(100, 2);
BENCHMARK(BM_SparseReorderFloat)->ArgPair(1000, 2); BENCHMARK(BM_SparseReorderFloat)->UseRealTime()->ArgPair(1000, 2);
BENCHMARK(BM_SparseReorderFloat)->ArgPair(10000, 2); BENCHMARK(BM_SparseReorderFloat)->UseRealTime()->ArgPair(10000, 2);
BENCHMARK(BM_SparseReorderFloat)->ArgPair(100000, 2); BENCHMARK(BM_SparseReorderFloat)->UseRealTime()->ArgPair(100000, 2);
BENCHMARK(BM_SparseReorderFloat)->ArgPair(10, 3); BENCHMARK(BM_SparseReorderFloat)->UseRealTime()->ArgPair(10, 3);
BENCHMARK(BM_SparseReorderFloat)->ArgPair(100, 3); BENCHMARK(BM_SparseReorderFloat)->UseRealTime()->ArgPair(100, 3);
BENCHMARK(BM_SparseReorderFloat)->ArgPair(1000, 3); BENCHMARK(BM_SparseReorderFloat)->UseRealTime()->ArgPair(1000, 3);
BENCHMARK(BM_SparseReorderFloat)->ArgPair(10000, 3); BENCHMARK(BM_SparseReorderFloat)->UseRealTime()->ArgPair(10000, 3);
BENCHMARK(BM_SparseReorderFloat)->ArgPair(100000, 3); BENCHMARK(BM_SparseReorderFloat)->UseRealTime()->ArgPair(100000, 3);
BENCHMARK(BM_SparseReorderString)->ArgPair(10, 2); BENCHMARK(BM_SparseReorderString)->UseRealTime()->ArgPair(10, 2);
BENCHMARK(BM_SparseReorderString)->ArgPair(100, 2); BENCHMARK(BM_SparseReorderString)->UseRealTime()->ArgPair(100, 2);
BENCHMARK(BM_SparseReorderString)->ArgPair(1000, 2); BENCHMARK(BM_SparseReorderString)->UseRealTime()->ArgPair(1000, 2);
BENCHMARK(BM_SparseReorderString)->ArgPair(10000, 2); BENCHMARK(BM_SparseReorderString)->UseRealTime()->ArgPair(10000, 2);
BENCHMARK(BM_SparseReorderString)->ArgPair(10, 3); BENCHMARK(BM_SparseReorderString)->UseRealTime()->ArgPair(10, 3);
BENCHMARK(BM_SparseReorderString)->ArgPair(100, 3); BENCHMARK(BM_SparseReorderString)->UseRealTime()->ArgPair(100, 3);
BENCHMARK(BM_SparseReorderString)->ArgPair(1000, 3); BENCHMARK(BM_SparseReorderString)->UseRealTime()->ArgPair(1000, 3);
BENCHMARK(BM_SparseReorderString)->ArgPair(10000, 3); BENCHMARK(BM_SparseReorderString)->UseRealTime()->ArgPair(10000, 3);
} // namespace } // namespace
} // namespace sparse } // namespace sparse

View File

@ -144,12 +144,14 @@ TEST(TensorSliceSetTest, QueryMetaTwoD) {
} }
} }
static void BM_RegisterOneByOne(int parts) { static void BM_RegisterOneByOne(::testing::benchmark::State& state) {
TensorShape shape({parts, 41}); TensorShape shape({static_cast<int>(state.max_iterations), 41});
TensorSliceSet slice_set(shape, DT_INT32); TensorSliceSet slice_set(shape, DT_INT32);
for (int i = 0; i < parts; ++i) { int i = 0;
for (auto s : state) {
TensorSlice part({{i, 1}, {0, -1}}); TensorSlice part({{i, 1}, {0, -1}});
TF_CHECK_OK(slice_set.Register(part, part.DebugString())); TF_CHECK_OK(slice_set.Register(part, part.DebugString()));
++i;
} }
} }