bench.cc 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. #include <signal.h>
  3. #include <ctime>
  4. #include <chrono>
  5. #include <rethinkdb.h>
  6. namespace R = RethinkDB;
  7. std::unique_ptr<R::Connection> conn;
  8. int main() {
  9. signal(SIGPIPE, SIG_IGN);
  10. try {
  11. conn = R::connect();
  12. } catch(const R::Error& error) {
  13. printf("FAILURE: could not connect to localhost:28015: %s\n", error.message.c_str());
  14. return 1;
  15. }
  16. try {
  17. printf("running test...\n");
  18. auto start = std::chrono::steady_clock::now();
  19. R::Datum d = R::range(1, 1000000)
  20. .map([]() { return R::object("test", "hello", "data", "world"); })
  21. .run(*conn);
  22. auto end = std::chrono::steady_clock::now();
  23. auto diff = end - start;
  24. printf("result size: %d\n", (int)d.get_array()->size());
  25. printf("completed in %f ms\n", std::chrono::duration<double, std::milli>(diff).count());
  26. } catch (const R::Error& error) {
  27. printf("FAILURE: uncaught exception: %s\n", error.message.c_str());
  28. return 1;
  29. }
  30. }
  31. */
  32. #include <iostream>
  33. #include <rethinkdb.h>
  34. namespace R = RethinkDB;
  35. int main() {
  36. auto conn = R::connect();
  37. if (!conn) {
  38. std::cerr << "Could not connect to server\n";
  39. return 1;
  40. }
  41. std::cout << "Connected" << std::endl;
  42. R::Cursor databases = R::db_list().run(*conn);
  43. for (R::Datum const& db : databases) {
  44. std::cout << *db.get_string() << '\n';
  45. }
  46. return 0;
  47. }