[svn] commit: r3164 - /branches/trac365/src/lib/bench/example/search_bench.cc
BIND 10 source code commits
bind10-changes at lists.isc.org
Sun Oct 10 12:32:55 UTC 2010
Author: jinmei
Date: Sun Oct 10 12:32:55 2010
New Revision: 3164
Log:
made sure compiler optimization wouldn't skip searches by checking the search result.
Modified:
branches/trac365/src/lib/bench/example/search_bench.cc
Modified: branches/trac365/src/lib/bench/example/search_bench.cc
==============================================================================
--- branches/trac365/src/lib/bench/example/search_bench.cc (original)
+++ branches/trac365/src/lib/bench/example/search_bench.cc Sun Oct 10 12:32:55 2010
@@ -16,6 +16,7 @@
#include <unistd.h> // for getpid
+#include <cassert>
#include <cstdlib> // for rand
#include <algorithm>
#include <iostream>
@@ -42,9 +43,11 @@
vector<int>::const_iterator end_key = keys_.end();
for (iter = keys_.begin(); iter != end_key; ++iter) {
if (Sorted) {
- binary_search(data_.begin(), data_.end(), *iter);
+ // perform simple sanity check with assert() to ensure
+ // compiler optimization won't skip the search.
+ assert(binary_search(data_.begin(), data_.end(), *iter));
} else {
- find(data_.begin(), data_.end(), *iter);
+ assert(find(data_.begin(), data_.end(), *iter) != data_.end());
}
}
return (keys_.size());
@@ -63,7 +66,7 @@
vector<int>::const_iterator iter;
vector<int>::const_iterator end_key = keys_.end();
for (iter = keys_.begin(); iter != end_key; ++iter) {
- data_.find(*iter);
+ assert(data_.find(*iter) != data_.end());
}
return (keys_.size());
}
More information about the bind10-changes
mailing list