Fix all the comparison issue in fb dev servers

main
Kai Liu 11 years ago
parent 113a08c929
commit b40c052bfa
  1. 2
      util/autovector.h
  2. 15
      util/autovector_test.cc

@ -6,7 +6,7 @@
#include <algorithm> #include <algorithm>
#include <cassert> #include <cassert>
#include <exception> #include <stdexcept>
#include <iterator> #include <iterator>
#include <vector> #include <vector>

@ -48,7 +48,7 @@ TEST(AutoVectorTest, PushBackAndPopBack) {
} }
TEST(AutoVectorTest, EmplaceBack) { TEST(AutoVectorTest, EmplaceBack) {
typedef std::pair<int, std::string> ValueType; typedef std::pair<size_t, std::string> ValueType;
autovector<ValueType, kSize> vec; autovector<ValueType, kSize> vec;
for (size_t i = 0; i < 1000 * kSize; ++i) { for (size_t i = 0; i < 1000 * kSize; ++i) {
@ -143,18 +143,19 @@ TEST(AutoVectorTest, Iterators) {
// HACK: make sure -> works // HACK: make sure -> works
ASSERT_TRUE(!old->empty()); ASSERT_TRUE(!old->empty());
ASSERT_EQ(old_val, *old); ASSERT_EQ(old_val, *old);
ASSERT_TRUE(old_val != *pos); ASSERT_TRUE(pos == vec.end() || old_val != *pos);
} }
pos = vec.begin(); pos = vec.begin();
typedef autovector<std::string>::difference_type diff_type; for (size_t i = 0; i < vec.size(); i += 2) {
for (diff_type i = 0; i < vec.size(); i += 2) {
// Cannot use ASSERT_EQ since that macro depends on iostream serialization // Cannot use ASSERT_EQ since that macro depends on iostream serialization
ASSERT_TRUE(pos + 2 - 2 == pos); ASSERT_TRUE(pos + 2 - 2 == pos);
pos += 2; pos += 2;
ASSERT_TRUE(i + 2 == pos - vec.begin());
ASSERT_TRUE(pos >= vec.begin()); ASSERT_TRUE(pos >= vec.begin());
ASSERT_TRUE(pos <= vec.end()); ASSERT_TRUE(pos <= vec.end());
size_t diff = static_cast<size_t>(pos - vec.begin());
ASSERT_EQ(i + 2, diff);
} }
} }
@ -191,7 +192,7 @@ void BenchmarkVectorCreationAndInsertion(
} }
template <class TVector> template <class TVector>
void BenchmarkSequenceAccess(string name, size_t ops, size_t elem_size) { size_t BenchmarkSequenceAccess(string name, size_t ops, size_t elem_size) {
TVector v; TVector v;
for (const auto& item : GetTestKeys(elem_size)) { for (const auto& item : GetTestKeys(elem_size)) {
v.push_back(item); v.push_back(item);
@ -211,6 +212,8 @@ void BenchmarkSequenceAccess(string name, size_t ops, size_t elem_size) {
cout << "performed " << ops << " sequence access against " << name << "\n\t" cout << "performed " << ops << " sequence access against " << name << "\n\t"
<< "size: " << elem_size << "\n\t" << "size: " << elem_size << "\n\t"
<< "total time elapsed: " << elapsed << " (ns)" << endl; << "total time elapsed: " << elapsed << " (ns)" << endl;
// HACK avoid compiler's optimization to ignore total
return total;
} }
// This test case only reports the performance between std::vector<string> // This test case only reports the performance between std::vector<string>

Loading…
Cancel
Save