Skip to content

Instantly share code, notes, and snippets.

@fgalan
Created June 10, 2015 12:09
Show Gist options
  • Save fgalan/d6e1b7edcc9a64728bd1 to your computer and use it in GitHub Desktop.
Save fgalan/d6e1b7edcc9a64728bd1 to your computer and use it in GitHub Desktop.
wc-test.cpp
#include <cstdlib>
#include <iostream>
#include <stdlib.h>
#include "mongo/client/dbclient.h"
#include "mongo/bson/bson.h"
// To build this program:
// g++ wc-test.cpp -pthread -lmongoclient -lboost_thread-mt -lboost_system -lboost_regex -o wc-test
int main() {
srand(0);
time_t start, end;
// Set connection
mongo::client::initialize();
mongo::WriteConcern wc1 = mongo::WriteConcern::acknowledged;
mongo::WriteConcern wc0 = mongo::WriteConcern::unacknowledged;
mongo::DBClientConnection c;
c.connect("localhost");
mongo::BSONObj result;
c.runCommand("admin", BSON("buildinfo" << 1), result);
std::cout << "MongoDB version: " << result.getStringField("version") << std::endl;
// Do the test with 'unacknowledged'
c.setWriteConcern(wc0);
time(&start);
for (int i = 0; i < 1000000; i++) {
c.insert("test.x", BSON("x" << rand()));
}
time(&end);
std::cout << "Duration (unacknowledged): " << difftime(end, start) << std::endl;
// Do the test with 'acknowledged'
c.setWriteConcern(wc1);
time(&start);
for (int i = 0; i < 1000000; i++) {
c.insert("test.x", BSON("x" << rand()));
}
time(&end);
std::cout << "Duration (acknowledged): " << difftime(end, start) << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment