Skip to content

Instantly share code, notes, and snippets.

@AtnNn
Created March 19, 2016 22:55
Show Gist options
  • Save AtnNn/c7a8cc3df2c47ce6d007 to your computer and use it in GitHub Desktop.
Save AtnNn/c7a8cc3df2c47ce6d007 to your computer and use it in GitHub Desktop.
testing PostQueuedCompletionStatus
queueing 10 events: average 0.500000ms per call, dequeued
queueing 100 events: average 0.550000ms per call, dequeued
queueing 1000 events: average 0.568000ms per call, dequeued
queueing 10000 events: average 0.585400ms per call, dequeued
queueing 100000 events: average 0.568470ms per call, dequeued
queueing 1000000 events: average 0.436295ms per call, dequeued
queueing 10000000 events: average 0.444731ms per call, dequeued
queueing 100000000 events: average 0.452936ms per call^C
include "errors.hpp"
#include "windows.hpp"
#include "time.hpp"
#include "unittest/gtest.hpp"
TEST(Delme, Post){
HANDLE iocp = CreateIoCompletionPort(INVALID_HANDLE_VALUE, nullptr, 0, 1);
guarantee_winerr(iocp, "A");
for (int count = 10; ; count *= 10) {
printf("queueing %d events: ", count);
fflush(stdout);
microtime_t total = 0;
for (int i = 0; i < count; ++i) {
microtime_t before = current_microtime();
BOOL res = PostQueuedCompletionStatus(iocp, 0, 0, (OVERLAPPED*)i);
guarantee_winerr(res);
microtime_t after = current_microtime();
guarantee_winerr(res);
total += after - before;
}
printf("average %lfms per call", total / (double)count);
fflush(stdout);
DWORD bytes;
ULONG_PTR key;
OVERLAPPED* event;
for (int i = 0; i < count; ++i) {
BOOL res = GetQueuedCompletionStatus(iocp, &bytes, &key, &event, INFINITE);
guarantee_winerr(res);
EXPECT_EQ((int)event, i);
}
printf(", dequeued\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment