summaryrefslogtreecommitdiff
path: root/ext/librethinkdbxx/test/bench.cc
blob: e2843d4c57fc2106a1c26d625df5b54d07376155 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
#include <signal.h>
#include <ctime>
#include <chrono>
#include <rethinkdb.h>

namespace R = RethinkDB;
std::unique_ptr<R::Connection> conn;

int main() {
    signal(SIGPIPE, SIG_IGN);
    try {
        conn = R::connect();
    } catch(const R::Error& error) {
        printf("FAILURE: could not connect to localhost:28015: %s\n", error.message.c_str());
        return 1;
    }

    try {
        printf("running test...\n");
        auto start = std::chrono::steady_clock::now();
        R::Datum d = R::range(1, 1000000)
          .map([]() { return R::object("test", "hello", "data", "world"); })
          .run(*conn);
        auto end = std::chrono::steady_clock::now();
        auto diff = end - start;

        printf("result size: %d\n", (int)d.get_array()->size());
        printf("completed in %f ms\n", std::chrono::duration<double, std::milli>(diff).count());
    } catch (const R::Error& error) {
        printf("FAILURE: uncaught exception: %s\n", error.message.c_str());
        return 1;
    }
}
*/

#include <iostream>
#include <rethinkdb.h>

namespace R = RethinkDB;

int main() {
    auto conn = R::connect();
    if (!conn) {
        std::cerr << "Could not connect to server\n";
        return 1;
    }

    std::cout << "Connected" << std::endl;
    R::Cursor databases = R::db_list().run(*conn);
    for (R::Datum const& db : databases) {
        std::cout << *db.get_string() << '\n';
    }

    return 0;
}