diff options
author | Manjunath Kudlur <keveman@gmail.com> | 2015-11-06 16:27:58 -0800 |
---|---|---|
committer | Manjunath Kudlur <keveman@gmail.com> | 2015-11-06 16:27:58 -0800 |
commit | f41959ccb2d9d4c722fe8fc3351401d53bcf4900 (patch) | |
tree | ef0ca22cb2a5ac4bdec9d080d8e0788a53ed496d /tensorflow/core/lib/hash/hash_test.cc |
TensorFlow: Initial commit of TensorFlow library.
TensorFlow is an open source software library for numerical computation
using data flow graphs.
Base CL: 107276108
Diffstat (limited to 'tensorflow/core/lib/hash/hash_test.cc')
-rw-r--r-- | tensorflow/core/lib/hash/hash_test.cc | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/tensorflow/core/lib/hash/hash_test.cc b/tensorflow/core/lib/hash/hash_test.cc new file mode 100644 index 0000000000..9d3b970f3b --- /dev/null +++ b/tensorflow/core/lib/hash/hash_test.cc @@ -0,0 +1,64 @@ +#include <vector> + +#include "tensorflow/core/lib/hash/hash.h" +#include "tensorflow/core/platform/logging.h" +#include "tensorflow/core/platform/test_benchmark.h" +#include <gtest/gtest.h> + +namespace tensorflow { + +TEST(Hash, SignedUnsignedIssue) { + const unsigned char d1[1] = {0x62}; + const unsigned char d2[2] = {0xc3, 0x97}; + const unsigned char d3[3] = {0xe2, 0x99, 0xa5}; + const unsigned char d4[4] = {0xe1, 0x80, 0xb9, 0x32}; + const unsigned char d5[48] = { + 0x01, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, + 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x18, 0x28, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }; + + struct Case { + uint32 hash32; + uint64 hash64; + const unsigned char* data; + size_t size; + uint32 seed; + }; + + for (Case c : std::vector<Case>{ + {0x471a8188u, 0x4c61ea3eeda4cb87ull, nullptr, 0, 0xbc9f1d34}, + {0xd615eba5u, 0x091309f7ef916c8aull, d1, sizeof(d1), 0xbc9f1d34}, + {0x0c3cccdau, 0xa815bcdf1d1af01cull, d2, sizeof(d2), 0xbc9f1d34}, + {0x3ba37e0eu, 0x02167564e4d06430ull, d3, sizeof(d3), 0xbc9f1d34}, + {0x16174eb3u, 0x8f7ed82ffc21071full, d4, sizeof(d4), 0xbc9f1d34}, + {0x98b1926cu, 0xce196580c97aff1eull, d5, sizeof(d5), 0x12345678}, + }) { + EXPECT_EQ(c.hash32, + Hash32(reinterpret_cast<const char*>(c.data), c.size, c.seed)); + EXPECT_EQ(c.hash64, + Hash64(reinterpret_cast<const char*>(c.data), c.size, c.seed)); + + // Check hashes with inputs aligned differently. + for (int align = 1; align <= 7; align++) { + std::string input(align, 'x'); + input.append(reinterpret_cast<const char*>(c.data), c.size); + EXPECT_EQ(c.hash32, Hash32(&input[align], c.size, c.seed)); + EXPECT_EQ(c.hash64, Hash64(&input[align], c.size, c.seed)); + } + } +} + +static void BM_Hash32(int iters, int len) { + std::string input(len, 'x'); + uint32 h = 0; + for (int i = 0; i < iters; i++) { + h = Hash32(input.data(), len, 1); + } + testing::BytesProcessed(static_cast<int64>(iters) * len); + VLOG(1) << h; +} +BENCHMARK(BM_Hash32)->Range(1, 1024); + +} // namespace tensorflow |