assert(end.tv_nsec >= start.tv_nsec);
return end.tv_nsec - start.tv_nsec;
}
- assert(end.tv_sec > start.tv_sec &&
- (uint64_t)(end.tv_sec - start.tv_sec) <
+ assert(end.tv_sec > start.tv_sec);
+ auto diff = uint64_t(end.tv_sec - start.tv_sec);
+ assert(diff <
std::numeric_limits<uint64_t>::max() / 1000000000UL);
- return (end.tv_sec - start.tv_sec) * 1000000000UL
+ return diff * 1000000000UL
+ end.tv_nsec - start.tv_nsec;
}
static inline void unpackInto(const unsigned char* src,
uint16_t* dest,
size_t count) {
- for (int i = 0, hi = 1, lo = 0; i < count; i++) {
+ for (size_t i = 0, hi = 1, lo = 0; i < count; i++) {
dest[i] = unpack(src[hi], src[lo]);
hi += 2;
lo += 2;
void readRandomDevice(void* data, size_t size) {
// Keep it open for the duration of the program
static File randomDevice("/dev/urandom");
- PCHECK(readFull(randomDevice.fd(), data, size) == size);
+ auto bytesRead = readFull(randomDevice.fd(), data, size);
+ PCHECK(bytesRead >= 0 && size_t(bytesRead) == size);
}
class BufferedRandomDevice {
throw std::runtime_error(
to<std::string>("Invalid format string; snprintf returned negative "
"with format string: ", format));
- } else if (bytes_used < remaining) {
+ } else if (size_t(bytes_used) < remaining) {
// There was enough room, just shrink and return.
output.resize(write_point + bytes_used);
} else {
bytes_used = vsnprintf(&output[write_point], remaining, format,
args_copy);
va_end(args_copy);
- if (bytes_used + 1 != remaining) {
+ if (size_t(bytes_used) + 1 != remaining) {
throw std::runtime_error(
to<std::string>("vsnprint retry did not manage to work "
"with format string: ", format));
// Copy pointers to the given strings in a format suitable for posix_spawn
std::unique_ptr<const char*[]> cloneStrings(const std::vector<std::string>& s) {
std::unique_ptr<const char*[]> d(new const char*[s.size() + 1]);
- for (int i = 0; i < s.size(); i++) {
+ for (size_t i = 0; i < s.size(); i++) {
d[i] = s[i].c_str();
}
d[s.size()] = nullptr;
} while (r == -1 && errno == EINTR);
checkUnixError(r, "poll");
- for (int i = 0; i < pipes_.size(); ++i) {
+ for (size_t i = 0; i < pipes_.size(); ++i) {
auto& p = pipes_[i];
DCHECK_EQ(fds[i].fd, p.parentFd);
short events = fds[i].revents;
const int8_t* p = begin;
uint64_t val = 0;
- if (LIKELY(end - begin >= kMaxVarintLength64)) { // fast path
+ // end is always greater than or equal to begin, so this subtraction is safe
+ if (LIKELY(size_t(end - begin) >= kMaxVarintLength64)) { // fast path
int64_t b;
do {
b = *p++; val = (b & 0x7f) ; if (b >= 0) break;
/// Returns the first decimal number in the string, or throws an exception
/// if the string does not start with a number terminated by ',', '-',
/// '\n', or eos.
-static ssize_t parseLeadingNumber(const std::string& line) {
+static size_t parseLeadingNumber(const std::string& line) {
auto raw = line.c_str();
char *end;
- unsigned val = strtoul(raw, &end, 10);
+ unsigned long val = strtoul(raw, &end, 10);
if (end == raw || (*end != ',' && *end != '-' && *end != '\n')) {
throw std::runtime_error(to<std::string>(
"error parsing list '", line, "'").c_str());
// to each other than entries that are far away. For striping we want
// the inverse map, since we are starting with the cpu
std::vector<size_t> indexes(cpus.size());
- for (int i = 0; i < cpus.size(); ++i) {
+ for (size_t i = 0; i < cpus.size(); ++i) {
indexes[cpus[i]] = i;
}
<< (info.frames.size() == 1 ? " frame" : " frames")
<< ")\n";
try {
- ssize_t frameCount = info.frames.size();
+ size_t frameCount = info.frames.size();
// Skip our own internal frames
static constexpr size_t skip = 3;
::close(fd);
};
- for (int i = 0; i < specs.size(); i++) {
+ for (size_t i = 0; i < specs.size(); i++) {
auto buf = allocateAligned(specs[i].size);
op.pread(fd, buf.get(), specs[i].size, specs[i].start);
aioReader.submit(&op);
if (multithreaded) {
threads.reserve(specs.size());
}
- for (int i = 0; i < specs.size(); i++) {
+ for (size_t i = 0; i < specs.size(); i++) {
bufs.push_back(allocateAligned(specs[i].size));
}
- auto submit = [&] (int i) {
+ auto submit = [&] (size_t i) {
ops[i].pread(fd, bufs[i].get(), specs[i].size, specs[i].start);
aioReader.submit(&ops[i]);
};
- for (int i = 0; i < specs.size(); i++) {
+ for (size_t i = 0; i < specs.size(); i++) {
if (multithreaded) {
threads.emplace_back([&submit, i] { submit(i); });
} else {
EXPECT_NE(nrRead, 0);
remaining -= nrRead;
- for (int i = 0; i < nrRead; i++) {
+ for (size_t i = 0; i < nrRead; i++) {
int id = completed[i] - ops.get();
EXPECT_GE(id, 0);
EXPECT_LT(id, specs.size());
EXPECT_EQ(specs.size(), aioReader.totalSubmits());
EXPECT_EQ(aioReader.pending(), 0);
- for (int i = 0; i < pending.size(); i++) {
+ for (size_t i = 0; i < pending.size(); i++) {
EXPECT_FALSE(pending[i]);
}
}
SCOPE_EXIT {
::close(fd);
};
- for (int i = 0; i < specs.size(); i++) {
+ for (size_t i = 0; i < specs.size(); i++) {
bufs.push_back(allocateAligned(specs[i].size));
ops[i].pread(fd, bufs[i].get(), specs[i].size, specs[i].start);
aioQueue.submit(&ops[i]);
EXPECT_NE(nrRead, 0);
remaining -= nrRead;
- for (int i = 0; i < nrRead; i++) {
+ for (size_t i = 0; i < nrRead; i++) {
int id = completed[i] - ops.get();
EXPECT_GE(id, 0);
EXPECT_LT(id, specs.size());
EXPECT_EQ(specs.size(), aioReader.totalSubmits());
EXPECT_EQ(aioReader.pending(), 0);
EXPECT_EQ(aioQueue.queued(), 0);
- for (int i = 0; i < pending.size(); i++) {
+ for (size_t i = 0; i < pending.size(); i++) {
EXPECT_FALSE(pending[i]);
}
}
} else {
print("(safe mode, symbolizer not available)\n");
AddressFormatter formatter;
- for (ssize_t i = 0; i < addresses.frameCount; ++i) {
+ for (size_t i = 0; i < addresses.frameCount; ++i) {
print(formatter.format(addresses.addresses[i]));
print("\n");
}
return -1;
}
++addresses;
- ssize_t count = 1;
+ size_t count = 1;
for (; count != maxAddresses; ++count, ++addresses) {
int r = unw_step(&cursor);
if (r < 0) {
};
BENCHMARK(NormalSingleton, n) {
- for (int i = 0; i < n; ++i) {
+ for (size_t i = 0; i < n; ++i) {
doNotOptimizeAway(getNormalSingleton());
}
}
BENCHMARK_RELATIVE(MeyersSingleton, n) {
- for (int i = 0; i < n; ++i) {
+ for (size_t i = 0; i < n; ++i) {
doNotOptimizeAway(getMeyersSingleton());
}
}
nullptr, nullptr, &benchmark_vault);
benchmark_vault.registrationComplete();
- for (int i = 0; i < n; ++i) {
+ for (size_t i = 0; i < n; ++i) {
doNotOptimizeAway(Singleton<BenchmarkSingleton>::get(&benchmark_vault));
}
}
void CPUThreadPoolExecutor::stopThreads(size_t n) {
CHECK(stoppedThreads_.size() == 0);
threadsToStop_ = n;
- for (int i = 0; i < n; i++) {
+ for (size_t i = 0; i < n; i++) {
taskQueue_->add(CPUTask());
}
}
// threadListLock_ is writelocked
void IOThreadPoolExecutor::stopThreads(size_t n) {
- for (int i = 0; i < n; i++) {
+ for (size_t i = 0; i < n; i++) {
const auto ioThread = std::static_pointer_cast<IOThread>(
threadList_.get()[i]);
ioThread->shouldRun = false;
// threadListLock_ is writelocked
void ThreadPoolExecutor::addThreads(size_t n) {
std::vector<ThreadPtr> newThreads;
- for (int i = 0; i < n; i++) {
+ for (size_t i = 0; i < n; i++) {
newThreads.push_back(makeThread());
}
for (auto& thread : newThreads) {
CHECK(stoppedThreads_.size() == 0);
isJoin_ = isJoin;
stopThreads(n);
- for (int i = 0; i < n; i++) {
+ for (size_t i = 0; i < n; i++) {
auto thread = stoppedThreads_.take();
thread->handle.join();
threadList_.remove(thread);
PCHECK(::write(wfd, &x, 1) == 1); // signal startup
FILE* f = fdopen(wfd, "w");
PCHECK(f);
- for (int i = 1; i <= iters; ++i) {
- fprintf(f, "%d\n", i);
+ for (size_t i = 1; i <= iters; ++i) {
+ fprintf(f, "%zu\n", i);
}
fclose(f);
});
| sum;
folly::doNotOptimizeAway(result);
};
- for (int i = 0; i < kNumThreads; i++) {
+ for (size_t i = 0; i < kNumThreads; i++) {
workers.push_back(std::thread(fn));
}
for (auto& w : workers) { w.join(); }
splitter.flush();
EXPECT_EQ(outs.size(), pieces.size());
- for (int i = 0; i < outs.size(); ++i) {
+ for (size_t i = 0; i < outs.size(); ++i) {
EXPECT_EQ(outs[i], pieces[i]);
}
p.second,
actualUncompressedLength);
- if (n != actualUncompressedLength) {
+ if (n < 0 || uint64_t(n) != actualUncompressedLength) {
throw std::runtime_error(to<std::string>(
"LZ4 decompression returned invalid value ", n));
}
}
// vsnprintf() returns the number of characters that would be printed,
// not including the terminating nul.
- if (ret < length()) {
+ if (size_t(ret) < length()) {
// All of the data was successfully written.
append(ret);
return;
if (ret < 0) {
throw std::runtime_error("error formatting printf() data");
}
- if (ret >= length()) {
+ if (size_t(ret) >= length()) {
// This shouldn't ever happen.
throw std::runtime_error("unexpectedly out of buffer space on second "
"vsnprintf() attmept");
: range_(range),
fileId_(fileId),
recordAndPos_(ByteRange(), 0) {
- if (pos >= range_.size()) {
+ if (size_t(pos) >= range_.size()) {
+ // Note that this branch can execute if pos is negative as well.
recordAndPos_.second = off_t(-1);
range_.clear();
} else {
void ShutdownSocketSet::add(int fd) {
// Silently ignore any fds >= maxFd_, very unlikely
DCHECK_GE(fd, 0);
- if (fd >= maxFd_) {
+ if (size_t(fd) >= maxFd_) {
return;
}
void ShutdownSocketSet::remove(int fd) {
DCHECK_GE(fd, 0);
- if (fd >= maxFd_) {
+ if (size_t(fd) >= maxFd_) {
return;
}
int ShutdownSocketSet::close(int fd) {
DCHECK_GE(fd, 0);
- if (fd >= maxFd_) {
+ if (size_t(fd) >= maxFd_) {
return folly::closeNoInt(fd);
}
void ShutdownSocketSet::shutdown(int fd, bool abortive) {
DCHECK_GE(fd, 0);
- if (fd >= maxFd_) {
+ if (fd >= 0 && size_t(fd) >= maxFd_) {
doShutdown(fd, abortive);
return;
}
// completely filled the available buffer.
// Note that readCallback_ may have been uninstalled or changed inside
// readDataAvailable().
- if (bytesRead < buflen) {
+ if (size_t(bytesRead) < buflen) {
return;
}
} else if (bytesRead == READ_BLOCKING) {
const size_t numStrings=sizeof(strings)/sizeof(*strings);
size_t chainLength = 0;
- for(ssize_t i=0; i<numStrings; ++i) {
+ for(size_t i = 0; i < numStrings; ++i) {
queue.append(stringToIOBuf(strings[i], strlen(strings[i])));
checkConsistency(queue);
chainLength += strlen(strings[i]);
}
unique_ptr<IOBuf> first;
- for(ssize_t i=0; i<numStrings; ++i) {
+ for(size_t i = 0; i < numStrings; ++i) {
checkConsistency(queue);
EXPECT_EQ(chainLength, queue.front()->computeChainDataLength());
EXPECT_EQ(chainLength, queue.chainLength());
TemporaryFile file;
{
RecordIOWriter writer(File(file.fd()));
- for (int i = 0; i < kSize; ++i) { // record of size 0 should be ignored
+ for (size_t i = 0; i < kSize; ++i) { // record of size 0 should be ignored
writer.write(IOBuf::wrapBuffer(tmp, i));
}
}
{
RecordIOReader reader(File(file.fd()));
auto it = reader.begin();
- for (int i = 1; i < kSize; ++i) {
+ for (size_t i = 1; i < kSize; ++i) {
ASSERT_FALSE(it == reader.end());
EXPECT_EQ(StringPiece(tmp, i), sp((it++)->first));
}
}
typedef int32_t KeyT;
-typedef int64_t KeyTBig;
typedef int32_t ValueT;
typedef AtomicHashMap<KeyT,ValueT> AHMapT;
TEST(Ahm, grow) {
VLOG(1) << "Overhead: " << sizeof(AHArrayT) << " (array) " <<
sizeof(AHMapT) + sizeof(AHArrayT) << " (map/set) Bytes.";
- int numEntries = 10000;
+ uint64_t numEntries = 10000;
float sizeFactor = 0.46;
std::unique_ptr<AHMapT> m(new AHMapT(int(numEntries * sizeFactor), config));
EXPECT_GT(m->numSubMaps(), 1); // make sure we grew
success = true;
EXPECT_EQ(m->size(), numEntries);
- for (int i = 0; i < numEntries; i++) {
+ for (size_t i = 0; i < numEntries; i++) {
success &= (m->find(i)->second == genVal(i));
}
EXPECT_TRUE(success);
success = true;
KeyT key(0);
AHMapT::const_iterator retIt;
- for (uint64_t i = 0; i < numEntries; i++) {
+ for (int32_t i = 0; i < int32_t(numEntries); i++) {
retIt = m->find(i);
retIt = m->findAt(retIt.getIndex());
success &= (retIt->second == genVal(i));
+ // We use a uint32_t index so that this comparison is between two
+ // variables of the same type.
success &= (retIt->first == i);
}
EXPECT_TRUE(success);
std::unique_ptr<AHMapT> m(new AHMapT(int(numEntries * sizeFactor), config));
// load map - make sure we succeed and the index is accurate
- for (uint64_t i = 0; i < numEntries; i++) {
+ for (int i = 0; i < numEntries; i++) {
m->insert(RecordT(i, genVal(i)));
}
}
TEST(Ahm, basicErase) {
- int numEntries = 3000;
+ size_t numEntries = 3000;
std::unique_ptr<AHMapT> s(new AHMapT(numEntries, config));
// Iterate filling up the map and deleting all keys a few times
for (int iterations = 0; iterations < 4; ++iterations) {
// Testing insertion of keys
bool success = true;
- for (uint64_t i = 0; i < numEntries; ++i) {
+ for (size_t i = 0; i < numEntries; ++i) {
success &= !(s->count(i));
auto ret = s->insert(RecordT(i, i));
success &= s->count(i);
// Delete every key in the map and verify that the key is gone and the the
// size is correct.
success = true;
- for (uint64_t i = 0; i < numEntries; ++i) {
+ for (size_t i = 0; i < numEntries; ++i) {
success &= s->erase(i);
success &= (s->size() == numEntries - 1 - i);
success &= !(s->count(i));
susp.dismiss();
runThreadsCreatedAllThreads.store(true);
- for (int i = 0; i < threadIds.size(); ++i) {
+ for (size_t i = 0; i < threadIds.size(); ++i) {
pthread_join(threadIds[i], statuses == nullptr ? nullptr : &statuses[i]);
}
}
threadIds.push_back(tid);
}
}
- for (int i = 0; i < threadIds.size(); ++i) {
+ for (size_t i = 0; i < threadIds.size(); ++i) {
pthread_join(threadIds[i], nullptr);
}
VLOG(1) << "Ended up with " << globalAHM->numSubMaps() << " submaps";
threadIds.push_back(tid);
}
}
- for (int i = 0; i < threadIds.size(); i++) {
+ for (size_t i = 0; i < threadIds.size(); i++) {
pthread_join(threadIds[i], nullptr);
}
BENCHMARK(st_aha_find, iters) {
CHECK_LE(iters, FLAGS_numBMElements);
- for (int i = 0; i < iters; i++) {
+ for (size_t i = 0; i < iters; i++) {
KeyT key = randomizeKey(i);
folly::doNotOptimizeAway(globalAHA->find(key)->second);
}
BENCHMARK(st_ahm_find, iters) {
CHECK_LE(iters, FLAGS_numBMElements);
- for (int i = 0; i < iters; i++) {
+ for (size_t i = 0; i < iters; i++) {
KeyT key = randomizeKey(i);
folly::doNotOptimizeAway(globalAHM->find(key)->second);
}
BENCHMARK(st_ahm_miss, iters) {
CHECK_LE(iters, FLAGS_numBMElements);
- for (int i = 0; i < iters; i++) {
+ for (size_t i = 0; i < iters; i++) {
KeyT key = randomizeKey(i + iters * 100);
folly::doNotOptimizeAway(globalAHM->find(key) == globalAHM->end());
}
KeyT k;
BENCHMARK(st_baseline_modulus_and_random, iters) {
- for (int i = 0; i < iters; ++i) {
+ for (size_t i = 0; i < iters; ++i) {
k = randomizeKey(i) % iters;
}
}
std::unique_ptr<AHMapT> ahm(new AHMapT(int(iters * LF), config));
susp.dismiss();
- for (int i = 0; i < iters; i++) {
+ for (size_t i = 0; i < iters; i++) {
KeyT key = randomizeKey(i);
ahm->insert(key, genVal(key));
}
sem_init(a, 0, 0);
sem_init(b, 0, 0);
auto thr = std::thread([=]{
- for (int i = 0; i < iters; ++i) {
+ for (size_t i = 0; i < iters; ++i) {
sem_wait(a);
sem_post(b);
}
});
- for (int i = 0; i < iters; ++i) {
+ for (size_t i = 0; i < iters; ++i) {
sem_post(a);
sem_wait(b);
}
auto sl = skiplist.get();
susp.dismiss();
- for (int i = 0; i < iters; ++i) {
+ for (size_t i = 0; i < iters; ++i) {
SkipListAccessor accessor(sl);
}
}
l.init();
susp.dismiss();
- for (int i = 0; i < iters; ++i) {
+ for (size_t i = 0; i < iters; ++i) {
value->fetch_add(1, std::memory_order_relaxed);
if (dirty->load(std::memory_order_acquire) != 0) {
folly::MSLGuard g(l);
sets_[idx].erase(val);
}
- void runSkipList(int id, int iters) {
+ void runSkipList(int id, size_t iters) {
int sum = 0;
- for (int i = 0; i < iters; ++i) {
+ for (size_t i = 0; i < iters; ++i) {
sum += accessSkipList(id, i);
}
// VLOG(20) << sum;
}
- void runSet(int id, int iters) {
+ void runSet(size_t id, size_t iters) {
int sum = 0;
- for (int i = 0; i < iters; ++i) {
+ for (size_t i = 0; i < iters; ++i) {
sum += accessSet(id, i);
}
// VLOG(20) << sum;
}
- bool accessSkipList(int64_t id, int t) {
+ bool accessSkipList(int64_t id, size_t t) {
if (t > readValues_.size()) {
t = t % readValues_.size();
}
}
}
- bool accessSet(int64_t id, int t) {
+ bool accessSet(int64_t id, size_t t) {
if (t > readValues_.size()) {
t = t % readValues_.size();
}
<< ": could only create " << threads.size() << " threads out of "
<< numThreads;
}
- for (int i = 0; i < threads.size(); ++i) {
+ for (size_t i = 0; i < threads.size(); ++i) {
threads[i].join();
}
static double dValue = 345345345.435;
BENCHMARK(preallocateTestNoFloat, n) {
- for (int i=0; i < n; ++i) {
+ for (size_t i = 0; i < n; ++i) {
auto val1 = to<std::string>(bigInt, someString, stdString, otherString);
auto val3 = to<std::string>(reallyShort, smallInt);
auto val2 = to<std::string>(bigInt, stdString);
}
BENCHMARK(preallocateTestFloat, n) {
- for (int i=0; i < n; ++i) {
+ for (size_t i = 0; i < n; ++i) {
auto val1 = to<std::string>(stdString, ',', fValue, dValue);
auto val2 = to<std::string>(stdString, ',', dValue);
}
std::function<int(int)>
DeterministicSchedule::uniform(long seed) {
auto rand = std::make_shared<std::ranlux48>(seed);
- return [rand](int numActive) {
+ return [rand](size_t numActive) {
auto dist = std::uniform_int_distribution<int>(0, numActive - 1);
return dist(*rand);
};
{
}
- int operator()(int numActive) {
+ size_t operator()(size_t numActive) {
adjustPermSize(numActive);
if (stepsLeft_-- == 0) {
stepsLeft_ = stepsBetweenSelect_ - 1;
private:
std::function<int(int)> uniform_;
- const int subsetSize_;
+ const size_t subsetSize_;
const int stepsBetweenSelect_;
int stepsLeft_;
// only the first subsetSize_ is properly randomized
std::vector<int> perm_;
- void adjustPermSize(int numActive) {
+ void adjustPermSize(size_t numActive) {
if (perm_.size() > numActive) {
perm_.erase(std::remove_if(perm_.begin(), perm_.end(),
- [=](int x){ return x >= numActive; }), perm_.end());
+ [=](size_t x){ return x >= numActive; }), perm_.end());
} else {
while (perm_.size() < numActive) {
perm_.push_back(perm_.size());
}
void shufflePrefix() {
- for (int i = 0; i < std::min(int(perm_.size() - 1), subsetSize_); ++i) {
+ for (size_t i = 0; i < std::min(perm_.size() - 1, subsetSize_); ++i) {
int j = uniform_(perm_.size() - i) + i;
std::swap(perm_[i], perm_[j]);
}
std::function<int(int)>
DeterministicSchedule::uniformSubset(long seed, int n, int m) {
auto gen = std::make_shared<UniformSubset>(seed, n, m);
- return [=](int numActive) { return (*gen)(numActive); };
+ return [=](size_t numActive) { return (*gen)(numActive); };
}
void
*/
BENCHMARK(exception_ptr_create_and_test, iters) {
std::runtime_error e("payload");
- for (int i = 0; i < iters; ++i) {
+ for (size_t i = 0; i < iters; ++i) {
auto ep = std::make_exception_ptr(e);
assert(ep);
}
BENCHMARK_RELATIVE(exception_wrapper_create_and_test, iters) {
std::runtime_error e("payload");
- for (int i = 0; i < iters; ++i) {
+ for (size_t i = 0; i < iters; ++i) {
auto ew = folly::make_exception_wrapper<std::runtime_error>(e);
assert(ew);
}
threads.emplace_back([&go, iters] {
while (!go) { }
std::runtime_error e("payload");
- for (int i = 0; i < iters; ++i) {
+ for (size_t i = 0; i < iters; ++i) {
auto ep = std::make_exception_ptr(e);
assert(ep);
}
threads.emplace_back([&go, iters] {
while (!go) { }
std::runtime_error e("payload");
- for (int i = 0; i < iters; ++i) {
+ for (size_t i = 0; i < iters; ++i) {
auto ew = folly::make_exception_wrapper<std::runtime_error>(e);
assert(ew);
}
*/
BENCHMARK(exception_ptr_create_and_throw, iters) {
std::runtime_error e("payload");
- for (int i = 0; i < iters; ++i) {
+ for (size_t i = 0; i < iters; ++i) {
auto ep = std::make_exception_ptr(e);
try {
std::rethrow_exception(ep);
BENCHMARK_RELATIVE(exception_wrapper_create_and_throw, iters) {
std::runtime_error e("payload");
- for (int i = 0; i < iters; ++i) {
+ for (size_t i = 0; i < iters; ++i) {
auto ew = folly::make_exception_wrapper<std::runtime_error>(e);
try {
ew.throwException();
BENCHMARK_RELATIVE(exception_wrapper_create_and_cast, iters) {
std::runtime_error e("payload");
- for (int i = 0; i < iters; ++i) {
+ for (size_t i = 0; i < iters; ++i) {
auto ew = folly::make_exception_wrapper<std::runtime_error>(e);
assert(ew.is_compatible_with<std::runtime_error>());
}
threads.emplace_back([&go, iters] {
while (!go) { }
std::runtime_error e("payload");
- for (int i = 0; i < iters; ++i) {
+ for (size_t i = 0; i < iters; ++i) {
auto ep = std::make_exception_ptr(e);
try {
std::rethrow_exception(ep);
threads.emplace_back([&go, iters] {
while (!go) { }
std::runtime_error e("payload");
- for (int i = 0; i < iters; ++i) {
+ for (size_t i = 0; i < iters; ++i) {
auto ew = folly::make_exception_wrapper<std::runtime_error>(e);
try {
ew.throwException();
threads.emplace_back([&go, iters] {
while (!go) { }
std::runtime_error e("payload");
- for (int i = 0; i < iters; ++i) {
+ for (size_t i = 0; i < iters; ++i) {
auto ew = folly::make_exception_wrapper<std::runtime_error>(e);
assert(ew.is_compatible_with<std::runtime_error>());
}
* override-include-guard
*/
-void BENCHFUN(initRNG)(int iters, int) {
+void BENCHFUN(initRNG)(size_t iters, size_t) {
srand(seed);
}
BENCHMARK_PARAM(BENCHFUN(initRNG), 0);
-void BENCHFUN(defaultCtor)(int iters, int) {
+void BENCHFUN(defaultCtor)(size_t iters, size_t) {
FOR_EACH_RANGE (i, 0, iters) {
STRING s[4096];
doNotOptimizeAway(&s);
}
BENCHMARK_PARAM(BENCHFUN(defaultCtor), 0);
-void BENCHFUN(copyCtor)(int iters, int arg) {
+void BENCHFUN(copyCtor)(size_t iters, size_t arg) {
STRING s;
BENCHMARK_SUSPEND {
randomString(&s, arg);
}
BENCHMARK_PARAM(BENCHFUN(copyCtor), 32768);
-void BENCHFUN(ctorFromArray)(int iters, int arg) {
+void BENCHFUN(ctorFromArray)(size_t iters, size_t arg) {
STRING s;
BENCHMARK_SUSPEND {
randomString(&s, arg);
}
BENCHMARK_PARAM(BENCHFUN(ctorFromArray), 32768);
-void BENCHFUN(ctorFromTwoPointers)(int iters, int arg) {
+void BENCHFUN(ctorFromTwoPointers)(size_t iters, size_t arg) {
static STRING s;
BENCHMARK_SUSPEND {
if (s.size() < arg) s.resize(arg);
BENCHMARK_PARAM(BENCHFUN(ctorFromTwoPointers), 23);
BENCHMARK_PARAM(BENCHFUN(ctorFromTwoPointers), 24);
-void BENCHFUN(ctorFromChar)(int iters, int arg) {
+void BENCHFUN(ctorFromChar)(size_t iters, size_t arg) {
FOR_EACH_RANGE (i, 0, iters) {
STRING s1('a', arg);
doNotOptimizeAway(&s1);
}
BENCHMARK_PARAM(BENCHFUN(ctorFromChar), 1048576);
-void BENCHFUN(assignmentOp)(int iters, int arg) {
+void BENCHFUN(assignmentOp)(size_t iters, size_t arg) {
STRING s;
BENCHMARK_SUSPEND {
randomString(&s, arg);
}
BENCHMARK_PARAM(BENCHFUN(assignmentOp), 256);
-void BENCHFUN(assignmentFill)(int iters, int) {
+void BENCHFUN(assignmentFill)(size_t iters, size_t) {
STRING s;
FOR_EACH_RANGE (i, 0, iters) {
s = static_cast<char>(i);
}
BENCHMARK_PARAM(BENCHFUN(assignmentFill), 0);
-void BENCHFUN(resize)(int iters, int arg) {
+void BENCHFUN(resize)(size_t iters, size_t arg) {
STRING s;
FOR_EACH_RANGE (i, 0, iters) {
s.resize(random(0, arg));
}
BENCHMARK_PARAM(BENCHFUN(resize), 524288);
-void BENCHFUN(findSuccessful)(int iters, int arg) {
+void BENCHFUN(findSuccessful)(size_t iters, size_t arg) {
size_t pos, len;
STRING s;
}
BENCHMARK_PARAM(BENCHFUN(findSuccessful), 524288);
-void BENCHFUN(findUnsuccessful)(int iters, int arg) {
+void BENCHFUN(findUnsuccessful)(size_t iters, size_t arg) {
STRING s, s1;
BENCHMARK_SUSPEND {
}
BENCHMARK_PARAM(BENCHFUN(findUnsuccessful), 524288);
-void BENCHFUN(equality)(int iters, int arg) {
+void BENCHFUN(equality)(size_t iters, size_t arg) {
std::vector<STRING> haystack(arg);
BENCHMARK_SUSPEND {
}
BENCHMARK_PARAM(BENCHFUN(equality), 65536);
-void BENCHFUN(replace)(int iters, int arg) {
+void BENCHFUN(replace)(size_t iters, size_t arg) {
STRING s;
BENCHMARK_SUSPEND {
randomString(&s, arg);
}
BENCHMARK_PARAM(BENCHFUN(replace), 256);
-void BENCHFUN(push_back)(int iters, int arg) {
+void BENCHFUN(push_back)(size_t iters, size_t arg) {
FOR_EACH_RANGE (i, 0, iters) {
STRING s;
FOR_EACH_RANGE (j, 0, arg) {
BENCHMARK_PARAM(BENCHFUN(push_back), 127);
BENCHMARK_PARAM(BENCHFUN(push_back), 1024);
-void BENCHFUN(short_append)(int iters, int arg) {
+void BENCHFUN(short_append)(size_t iters, size_t arg) {
FOR_EACH_RANGE (i, 0, iters) {
STRING s;
FOR_EACH_RANGE (j, 0, arg) {
if (n <= 0) {
return n;
}
- if (n > count) {
+ if (size_t(n) > count) {
throw std::runtime_error("requested count too small");
}
memcpy(buf, data_.data(), n);
for (auto& p : readers_) {
std::string out(in_.size(), '\0');
EXPECT_EQ(p.first, wrapFull(p.second, 0, &out[0], out.size()));
- if (p.first != -1) {
+ if (p.first != (typeof(p.first))(-1)) {
EXPECT_EQ(in_.substr(0, p.first), out.substr(0, p.first));
}
}
for (auto& p : readers_) {
std::string out(in_.size(), '\0');
EXPECT_EQ(p.first, wrapFull(p.second, 0, &out[0], out.size(), off_t(42)));
- if (p.first != -1) {
+ if (p.first != (typeof(p.first))(-1)) {
EXPECT_EQ(in_.substr(0, p.first), out.substr(0, p.first));
}
}
auto iov = buf.iov();
EXPECT_EQ(p.first, wrapvFull(p.second, 0, iov.data(), iov.size()));
- if (p.first != -1) {
+ if (p.first != (typeof(p.first))(-1)) {
EXPECT_EQ(in_.substr(0, p.first), buf.join().substr(0, p.first));
}
}
auto iov = buf.iov();
EXPECT_EQ(p.first,
wrapvFull(p.second, 0, iov.data(), iov.size(), off_t(42)));
- if (p.first != -1) {
+ if (p.first != (typeof(p.first))(-1)) {
EXPECT_EQ(in_.substr(0, p.first), buf.join().substr(0, p.first));
}
}
std::map<int, std::string> bmMap; // For use in benchmarks below.
-void setupBenchmark(int iters) {
+void setupBenchmark(size_t iters) {
bmMap.clear();
- for (int i = 0; i < iters; ++i) {
+ for (size_t i = 0; i < iters; ++i) {
bmMap[i] = "teststring";
}
}
BENCHMARK(ForEachManual, iters) {
int sum = 1;
- for (auto i = 1; i < iters; ++i) {
+ for (size_t i = 1; i < iters; ++i) {
sum *= i;
}
doNotOptimizeAway(sum);
BENCHMARK(ForEachDescendingManual, iters) {
int sum = 1;
- for (auto i = iters; i-- > 1; ) {
+ for (size_t i = iters; i-- > 1; ) {
sum *= i;
}
doNotOptimizeAway(sum);
TEST_P(IPAddressByteAccessorTest, CheckBytes) {
auto addrData = GetParam();
IPAddress ip(addrData.address);
- auto i = 0;
+ size_t i = 0;
for (auto byitr = addrData.bytes.begin(); i < ip.byteCount(); ++i, ++byitr) {
EXPECT_EQ(*byitr, ip.getNthMSByte(i));
EXPECT_EQ(*byitr, ip.isV4() ?
//We will traverse the IPAddress bits from 0 to bitCount -1
auto bitr = folly::makeBitIterator(littleEndianAddrData.begin());
IPAddress ip(addrData.address);
- for (auto i = 0; i < ip.bitCount(); ++i) {
+ for (size_t i = 0; i < ip.bitCount(); ++i) {
auto msbIndex = ip.bitCount() - i - 1;
EXPECT_EQ(*bitr, ip.getNthMSBit(msbIndex));
EXPECT_EQ(*bitr, ip.isV4() ? ip.asV4().getNthMSBit(msbIndex) :
BENCHMARK(jsonSerialize, iters) {
folly::json::serialization_opts opts;
- for (int i = 0; i < iters; ++i) {
+ for (size_t i = 0; i < iters; ++i) {
folly::json::serialize(
"qwerty \xc2\x80 \xef\xbf\xbf poiuy"
"qwerty \xc2\x80 \xef\xbf\xbf poiuy"
folly::json::serialization_opts opts;
opts.encode_non_ascii = true;
- for (int i = 0; i < iters; ++i) {
+ for (size_t i = 0; i < iters; ++i) {
folly::json::serialize(
"qwerty \xc2\x80 \xef\xbf\xbf poiuy"
"qwerty \xc2\x80 \xef\xbf\xbf poiuy"
folly::json::serialization_opts opts;
opts.validate_utf8 = true;
- for (int i = 0; i < iters; ++i) {
+ for (size_t i = 0; i < iters; ++i) {
folly::json::serialize(
"qwerty \xc2\x80 \xef\xbf\xbf poiuy"
"qwerty \xc2\x80 \xef\xbf\xbf poiuy"
}
BENCHMARK(parseSmallStringWithUtf, iters) {
- for (int i = 0; i < iters << 4; ++i) {
+ for (size_t i = 0; i < iters << 4; ++i) {
parseJson("\"I \\u2665 UTF-8 thjasdhkjh blah blah blah\"");
}
}
BENCHMARK(parseNormalString, iters) {
- for (int i = 0; i < iters << 4; ++i) {
+ for (size_t i = 0; i < iters << 4; ++i) {
parseJson("\"akjhfk jhkjlakjhfk jhkjlakjhfk jhkjl akjhfk\"");
}
}
BENCHMARK(parseBigString, iters) {
- for (int i = 0; i < iters; ++i) {
+ for (size_t i = 0; i < iters; ++i) {
parseJson("\""
"akjhfk jhkjlakjhfk jhkjlakjhfk jhkjl akjhfk"
"akjhfk jhkjlakjhfk jhkjlakjhfk jhkjl akjhfk"
"{\"old_value\":40,\"changed\":true,\"opened\":false,\"foo\":[1,2,3,4,5,6]}"
);
- for (int i = 0; i < iters; i++) {
+ for (size_t i = 0; i < iters; i++) {
toJson(something);
}
}
LifoSem a;
LifoSem b;
auto thr = std::thread([&]{
- for (int i = 0; i < iters; ++i) {
+ for (size_t i = 0; i < iters; ++i) {
a.wait();
b.post();
}
});
- for (int i = 0; i < iters; ++i) {
+ for (size_t i = 0; i < iters; ++i) {
a.post();
b.wait();
}
BENCHMARK(lifo_sem_oneway, iters) {
LifoSem a;
auto thr = std::thread([&]{
- for (int i = 0; i < iters; ++i) {
+ for (size_t i = 0; i < iters; ++i) {
a.wait();
}
});
- for (int i = 0; i < iters; ++i) {
+ for (size_t i = 0; i < iters; ++i) {
a.post();
}
thr.join();
BENCHMARK(single_thread_lifo_post, iters) {
LifoSem sem;
- for (int n = 0; n < iters; ++n) {
+ for (size_t n = 0; n < iters; ++n) {
sem.post();
asm volatile ("":::"memory");
}
BENCHMARK(single_thread_lifo_wait, iters) {
LifoSem sem(iters);
- for (int n = 0; n < iters; ++n) {
+ for (size_t n = 0; n < iters; ++n) {
sem.wait();
asm volatile ("":::"memory");
}
BENCHMARK(single_thread_lifo_postwait, iters) {
LifoSem sem;
- for (int n = 0; n < iters; ++n) {
+ for (size_t n = 0; n < iters; ++n) {
sem.post();
asm volatile ("":::"memory");
sem.wait();
BENCHMARK(single_thread_lifo_trywait, iters) {
LifoSem sem;
- for (int n = 0; n < iters; ++n) {
+ for (size_t n = 0; n < iters; ++n) {
EXPECT_FALSE(sem.tryWait());
asm volatile ("":::"memory");
}
BENCHMARK(single_thread_posix_postwait, iters) {
sem_t sem;
EXPECT_EQ(sem_init(&sem, 0, 0), 0);
- for (int n = 0; n < iters; ++n) {
+ for (size_t n = 0; n < iters; ++n) {
EXPECT_EQ(sem_post(&sem), 0);
EXPECT_EQ(sem_wait(&sem), 0);
}
BENCHMARK(single_thread_posix_trywait, iters) {
sem_t sem;
EXPECT_EQ(sem_init(&sem, 0, 0), 0);
- for (int n = 0; n < iters; ++n) {
+ for (size_t n = 0; n < iters; ++n) {
EXPECT_EQ(sem_trywait(&sem), -1);
}
EXPECT_EQ(sem_destroy(&sem), 0);
}
bool atLeastOneIsGood = false;
- for (int i = 0; i < hist.size() - 1; ++i) {
+ for (size_t i = 0; i < hist.size() - 1; ++i) {
auto delta = hist[i + 1] - hist[i];
if (delta > std::chrono::milliseconds(5) &&
delta < std::chrono::milliseconds(15)) {
TEST(MPMCQueue, tryenq_capacity_test) {
for (size_t cap = 1; cap < 100; ++cap) {
MPMCQueue<int> cq(cap);
- for (int i = 0; i < cap; ++i) {
+ for (size_t i = 0; i < cap; ++i) {
EXPECT_TRUE(cq.write(i));
}
EXPECT_FALSE(cq.write(100));
v_.resize(4);
n_ = 0;
for (int i = 0; i < 4; i++) {
- for (int j = 0; j < IntNode::kElementCount; ++j, ++n_) {
+ for (size_t j = 0; j < IntNode::kElementCount; ++j, ++n_) {
v_[i].data()[j] = n_;
}
}
k = 0;
for (int i = 0; i < 4; i++) {
- for (int j = 0; j < IntNode::kElementCount; ++j, ++k) {
+ for (size_t j = 0; j < IntNode::kElementCount; ++j, ++k) {
EXPECT_EQ(k, v_[i].data()[j]);
}
}
v_.resize(4);
n_ = 0;
for (int i = 0; i < 4; i++) {
- for (int j = 0; j < PointNode::kElementCount; ++j, ++n_) {
+ for (size_t j = 0; j < PointNode::kElementCount; ++j, ++n_) {
auto& point = v_[i].data()[j];
point.x = n_;
point.y = n_ + 1;
s.push_back('a');
ffoTestString = s;
- for (int i = 0; i < ffoDelimSize; ++i) {
+ for (size_t i = 0; i < ffoDelimSize; ++i) {
// most delimiter sets are pretty small, but occasionally there could
// be a big one.
auto n = rnd() % 8 + 1;
template <class Func>
void findFirstOfRandom(Func func, size_t iters) {
- for (int i = 0; i < iters; ++i) {
+ for (size_t i = 0; i < iters; ++i) {
auto test = i % ffoDelim.size();
auto p = func(ffoTestString, ffoDelim[test]);
doNotOptimizeAway(p);
TYPED_TEST(NeedleFinderTest, Unaligned) {
// works correctly even if input buffers are not 16-byte aligned
string s = "0123456789ABCDEFGH";
- for (int i = 0; i < s.size(); ++i) {
+ for (size_t i = 0; i < s.size(); ++i) {
StringPiece a(s.c_str() + i);
for (int j = 0; j < s.size(); ++j) {
StringPiece b(s.c_str() + j);
const auto maxValue = std::numeric_limits<StringPiece::value_type>::max();
// make the size ~big to avoid any edge-case branches for tiny haystacks
const int haystackSize = 50;
- for (int i = minValue; i <= maxValue; i++) { // <=
+ for (size_t i = minValue; i <= maxValue; i++) { // <=
needles.push_back(i);
}
EXPECT_EQ(StringPiece::npos, this->find_first_byte_of("", needles));
- for (int i = minValue; i <= maxValue; i++) {
+ for (size_t i = minValue; i <= maxValue; i++) {
EXPECT_EQ(0, this->find_first_byte_of(string(haystackSize, i), needles));
}
needles.append("these are redundant characters");
EXPECT_EQ(StringPiece::npos, this->find_first_byte_of("", needles));
- for (int i = minValue; i <= maxValue; i++) {
+ for (size_t i = minValue; i <= maxValue; i++) {
EXPECT_EQ(0, this->find_first_byte_of(string(haystackSize, i), needles));
}
}
TYPED_TEST(NeedleFinderTest, Base) {
- for (int i = 0; i < 32; ++i) {
+ for (size_t i = 0; i < 32; ++i) {
for (int j = 0; j < 32; ++j) {
string s = string(i, 'X') + "abca" + string(i, 'X');
string delims = string(j, 'Y') + "a" + string(j, 'Y');
testRangeFunc(x, 4);
}
-std::string get_rand_str(
- int size, std::uniform_int_distribution<>& dist, std::mt19937& gen) {
+std::string get_rand_str(size_t size,
+ std::uniform_int_distribution<>& dist,
+ std::mt19937& gen) {
std::string ret(size, '\0');
- for (int i=0; i<size; ++i) {
+ for (size_t i = 0; i < size; ++i) {
ret[i] = static_cast<char>(dist(gen));
}
std::uniform_int_distribution<> dist('a', 'z');
for (int i=0; i < 100; ++i) {
- for (int j = 1; j <= msp.size(); ++j) {
+ for (size_t j = 1; j <= msp.size(); ++j) {
auto replacement = get_rand_str(j, dist, gen);
- for (int pos=0; pos < msp.size() - j; ++pos) {
+ for (size_t pos = 0; pos < msp.size() - j; ++pos) {
msp.replaceAt(pos, replacement);
str.replace(pos, replacement.size(), replacement);
EXPECT_EQ(msp.compare(str), 0);
std::uniform_int_distribution<> dist('A', 'Z');
for (int i=0; i < 100; ++i) {
- for (int j = 1; j <= orig.size(); ++j) {
+ for (size_t j = 1; j <= orig.size(); ++j) {
auto replacement = get_rand_str(j, dist, gen);
- for (int pos=0; pos < msp.size() - j; ++pos) {
+ for (size_t pos = 0; pos < msp.size() - j; ++pos) {
auto piece = orig.substr(pos, j);
EXPECT_EQ(msp.replaceAll(piece, replacement), 1);
EXPECT_EQ(msp.find(replacement), pos);
MSLGuard g(v.lock);
int first = v.ar[0];
- for (int i = 1; i < sizeof v.ar / sizeof i; ++i) {
+ for (size_t i = 1; i < sizeof v.ar / sizeof i; ++i) {
EXPECT_EQ(first, v.ar[i]);
}
BENCHMARK(splitOnSingleChar, iters) {
static const std::string line = "one:two:three:four";
- for (int i = 0; i < iters << 4; ++i) {
+ for (size_t i = 0; i < iters << 4; ++i) {
std::vector<StringPiece> pieces;
folly::split(':', line, pieces);
}
BENCHMARK(splitOnSingleCharFixed, iters) {
static const std::string line = "one:two:three:four";
- for (int i = 0; i < iters << 4; ++i) {
+ for (size_t i = 0; i < iters << 4; ++i) {
StringPiece a, b, c, d;
folly::split(':', line, a, b, c, d);
}
BENCHMARK(splitOnSingleCharFixedAllowExtra, iters) {
static const std::string line = "one:two:three:four";
- for (int i = 0; i < iters << 4; ++i) {
+ for (size_t i = 0; i < iters << 4; ++i) {
StringPiece a, b, c, d;
folly::split<false>(':', line, a, b, c, d);
}
BENCHMARK(splitStr, iters) {
static const std::string line = "one-*-two-*-three-*-four";
- for (int i = 0; i < iters << 4; ++i) {
+ for (size_t i = 0; i < iters << 4; ++i) {
std::vector<StringPiece> pieces;
folly::split("-*-", line, pieces);
}
BENCHMARK(splitStrFixed, iters) {
static const std::string line = "one-*-two-*-three-*-four";
- for (int i = 0; i < iters << 4; ++i) {
+ for (size_t i = 0; i < iters << 4; ++i) {
StringPiece a, b, c, d;
folly::split("-*-", line, a, b, c, d);
}
BENCHMARK(boost_splitOnSingleChar, iters) {
static const std::string line = "one:two:three:four";
bool(*pred)(char) = [] (char c) -> bool { return c == ':'; };
- for (int i = 0; i < iters << 4; ++i) {
+ for (size_t i = 0; i < iters << 4; ++i) {
std::vector<boost::iterator_range<std::string::const_iterator> > pieces;
boost::split(pieces, line, pred);
}
BENCHMARK(joinCharStr, iters) {
static const std::vector<std::string> input = {
"one", "two", "three", "four", "five", "six", "seven" };
- for (int i = 0; i < iters << 4; ++i) {
+ for (size_t i = 0; i < iters << 4; ++i) {
std::string output;
folly::join(':', input, output);
}
BENCHMARK(joinStrStr, iters) {
static const std::vector<std::string> input = {
"one", "two", "three", "four", "five", "six", "seven" };
- for (int i = 0; i < iters << 4; ++i) {
+ for (size_t i = 0; i < iters << 4; ++i) {
std::string output;
folly::join(":", input, output);
}
BENCHMARK(joinInt, iters) {
static const auto input = {
123, 456, 78910, 1112, 1314, 151, 61718 };
- for (int i = 0; i < iters << 4; ++i) {
+ for (size_t i = 0; i < iters << 4; ++i) {
std::string output;
folly::join(":", input, output);
}
const size_t numCopies = 100000;
auto iobuf = IOBuf::copyBuffer("this is a test\nanother line\n");
IOBufQueue input;
- for (int n = 0; n < numCopies; ++n) {
+ for (size_t n = 0; n < numCopies; ++n) {
input.append(iobuf->clone());
}
*/
BENCHMARK(init_uri_simple, iters) {
const fbstring s("http://localhost?&key1=foo&key2=&key3&=bar&=bar=&");
- for (int i = 0; i < iters; ++i) {
+ for (size_t i = 0; i < iters; ++i) {
Uri u(s);
}
}
BENCHMARK(init_uri_simple_with_query_parsing, iters) {
const fbstring s("http://localhost?&key1=foo&key2=&key3&=bar&=bar=&");
- for (int i = 0; i < iters; ++i) {
+ for (size_t i = 0; i < iters; ++i) {
Uri u(s);
u.getQueryParams();
}
"04nYX8N%46zzpv%999h&KGmBt988y=q4P57C-Dh-Nz-x_7-5oPxz%1gz3N03t6c7-R67N4DT"
"Y6-f98W1&Lts&%02dOty%8eEYEnLz4yexQQLnL4MGU2JFn3OcmXcatBcabZgBdDdy67hdgW"
"tYn4");
- for (int i = 0; i < iters; ++i) {
+ for (size_t i = 0; i < iters; ++i) {
Uri u(s);
}
}
"04nYX8N%46zzpv%999h&KGmBt988y=q4P57C-Dh-Nz-x_7-5oPxz%1gz3N03t6c7-R67N4DT"
"Y6-f98W1&Lts&%02dOty%8eEYEnLz4yexQQLnL4MGU2JFn3OcmXcatBcabZgBdDdy67hdgW"
"tYn4");
- for (int i = 0; i < iters; ++i) {
+ for (size_t i = 0; i < iters; ++i) {
Uri u(s);
u.getQueryParams();
}
for (size_t i = 0; i < kNumValues; ++i) {
int n = numBytes(rng);
uint64_t val = 0;
- for (size_t j = 0; j < n; ++j) {
+ for (int j = 0; j < n; ++j) {
val = (val << 8) + byte(rng);
}
gValues[i] = val;
// Directly invoking a function
BENCHMARK(fn_invoke, iters) {
- for (int n = 0; n < iters; ++n) {
+ for (size_t n = 0; n < iters; ++n) {
doNothing();
}
}
// Creating a function pointer and invoking it
BENCHMARK(fn_ptr_create_invoke, iters) {
- for (int n = 0; n < iters; ++n) {
+ for (size_t n = 0; n < iters; ++n) {
void (*fn)() = doNothing;
fn();
}
// Creating a std::function object from a function pointer, and invoking it
BENCHMARK(std_function_create_invoke, iters) {
- for (int n = 0; n < iters; ++n) {
+ for (size_t n = 0; n < iters; ++n) {
std::function<void()> fn = doNothing;
fn();
}
// Creating a pointer-to-member and invoking it
BENCHMARK(mem_fn_create_invoke, iters) {
TestClass tc;
- for (int n = 0; n < iters; ++n) {
+ for (size_t n = 0; n < iters; ++n) {
void (TestClass::*memfn)() = &TestClass::doNothing;
(tc.*memfn)();
}
// and invoking it
BENCHMARK(std_bind_create_invoke, iters) {
TestClass tc;
- for (int n = 0; n < iters; ++n) {
+ for (size_t n = 0; n < iters; ++n) {
std::function<void()> fn = std::bind(&TestClass::doNothing, &tc);
fn();
}
// Using std::bind directly to invoke a member function
BENCHMARK(std_bind_direct_invoke, iters) {
TestClass tc;
- for (int n = 0; n < iters; ++n) {
+ for (size_t n = 0; n < iters; ++n) {
auto fn = std::bind(&TestClass::doNothing, &tc);
fn();
}
// Using ScopeGuard to invoke a std::function
BENCHMARK(scope_guard_std_function, iters) {
std::function<void()> fn(doNothing);
- for (int n = 0; n < iters; ++n) {
+ for (size_t n = 0; n < iters; ++n) {
ScopeGuard g = makeGuard(fn);
}
}
// Using ScopeGuard to invoke a std::function,
// but create the ScopeGuard with an rvalue to a std::function
BENCHMARK(scope_guard_std_function_rvalue, iters) {
- for (int n = 0; n < iters; ++n) {
+ for (size_t n = 0; n < iters; ++n) {
ScopeGuard g = makeGuard(std::function<void()>(doNothing));
}
}
// Using ScopeGuard to invoke a function pointer
BENCHMARK(scope_guard_fn_ptr, iters) {
- for (int n = 0; n < iters; ++n) {
+ for (size_t n = 0; n < iters; ++n) {
ScopeGuard g = makeGuard(doNothing);
}
}
// Using ScopeGuard to invoke a lambda that does nothing
BENCHMARK(scope_guard_lambda_noop, iters) {
- for (int n = 0; n < iters; ++n) {
+ for (size_t n = 0; n < iters; ++n) {
ScopeGuard g = makeGuard([] {});
}
}
// Using ScopeGuard to invoke a lambda that invokes a function
BENCHMARK(scope_guard_lambda_function, iters) {
- for (int n = 0; n < iters; ++n) {
+ for (size_t n = 0; n < iters; ++n) {
ScopeGuard g = makeGuard([] { doNothing(); });
}
}
// Using ScopeGuard to invoke a lambda that modifies a local variable
BENCHMARK(scope_guard_lambda_local_var, iters) {
uint32_t count = 0;
- for (int n = 0; n < iters; ++n) {
+ for (size_t n = 0; n < iters; ++n) {
ScopeGuard g = makeGuard([&] {
// Increment count if n is odd. Without this conditional check
// (i.e., if we just increment count each time through the loop),
BENCHMARK_DRAW_LINE()
BENCHMARK(throw_exception, iters) {
- for (int n = 0; n < iters; ++n) {
+ for (size_t n = 0; n < iters; ++n) {
try {
throwException();
} catch (const std::exception& ex) {
}
BENCHMARK(catch_no_exception, iters) {
- for (int n = 0; n < iters; ++n) {
+ for (size_t n = 0; n < iters; ++n) {
try {
doNothing();
} catch (const std::exception& ex) {
}
BENCHMARK(return_exc_ptr, iters) {
- for (int n = 0; n < iters; ++n) {
+ for (size_t n = 0; n < iters; ++n) {
returnExceptionPtr();
}
}
BENCHMARK(exc_ptr_param_return, iters) {
- for (int n = 0; n < iters; ++n) {
+ for (size_t n = 0; n < iters; ++n) {
std::exception_ptr ex;
exceptionPtrReturnParam(&ex);
}
}
BENCHMARK(exc_ptr_param_return_null, iters) {
- for (int n = 0; n < iters; ++n) {
+ for (size_t n = 0; n < iters; ++n) {
exceptionPtrReturnParam(nullptr);
}
}
BENCHMARK(return_string, iters) {
- for (int n = 0; n < iters; ++n) {
+ for (size_t n = 0; n < iters; ++n) {
returnString();
}
}
BENCHMARK(return_string_noexcept, iters) {
- for (int n = 0; n < iters; ++n) {
+ for (size_t n = 0; n < iters; ++n) {
returnStringNoExcept();
}
}
BENCHMARK(return_code, iters) {
- for (int n = 0; n < iters; ++n) {
+ for (size_t n = 0; n < iters; ++n) {
returnCode(false);
}
}
BENCHMARK(return_code_noexcept, iters) {
- for (int n = 0; n < iters; ++n) {
+ for (size_t n = 0; n < iters; ++n) {
returnCodeNoExcept(false);
}
}
folly::small_vector<int> someVec(3, 3);
someVec.insert(someVec.begin(), 12, 12);
EXPECT_EQ(someVec.size(), 15);
- for (int i = 0; i < someVec.size(); ++i) {
+ for (size_t i = 0; i < someVec.size(); ++i) {
if (i < 12) {
EXPECT_EQ(someVec[i], 12);
} else {
auto capacity = vec.capacity();
auto oldSize = vec.size();
- for (int i = 0; i < oldSize; ++i) {
+ for (size_t i = 0; i < oldSize; ++i) {
vec.erase(vec.begin() + (std::rand() % vec.size()));
EXPECT_EQ(vec.capacity(), capacity);
}