diff --git a/util/autovector.h b/util/autovector.h index 2b9cb40e9..9998e2956 100644 --- a/util/autovector.h +++ b/util/autovector.h @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include diff --git a/util/autovector_test.cc b/util/autovector_test.cc index 67fb67b05..6d709a374 100644 --- a/util/autovector_test.cc +++ b/util/autovector_test.cc @@ -48,7 +48,7 @@ TEST(AutoVectorTest, PushBackAndPopBack) { } TEST(AutoVectorTest, EmplaceBack) { - typedef std::pair ValueType; + typedef std::pair ValueType; autovector vec; for (size_t i = 0; i < 1000 * kSize; ++i) { @@ -143,18 +143,19 @@ TEST(AutoVectorTest, Iterators) { // HACK: make sure -> works ASSERT_TRUE(!old->empty()); ASSERT_EQ(old_val, *old); - ASSERT_TRUE(old_val != *pos); + ASSERT_TRUE(pos == vec.end() || old_val != *pos); } pos = vec.begin(); - typedef autovector::difference_type diff_type; - for (diff_type i = 0; i < vec.size(); i += 2) { + for (size_t i = 0; i < vec.size(); i += 2) { // Cannot use ASSERT_EQ since that macro depends on iostream serialization ASSERT_TRUE(pos + 2 - 2 == pos); pos += 2; - ASSERT_TRUE(i + 2 == pos - vec.begin()); ASSERT_TRUE(pos >= vec.begin()); ASSERT_TRUE(pos <= vec.end()); + + size_t diff = static_cast(pos - vec.begin()); + ASSERT_EQ(i + 2, diff); } } @@ -191,7 +192,7 @@ void BenchmarkVectorCreationAndInsertion( } template -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; for (const auto& item : GetTestKeys(elem_size)) { 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" << "size: " << elem_size << "\n\t" << "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