profile.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include <time.h>
  2. #include "graph.h"
  3. #ifndef NT
  4. #define NT 100000
  5. #endif
  6. static LSUP_Triple *
  7. generate_triples()
  8. {
  9. LSUP_Triple *trp;
  10. CRITICAL(trp = malloc(NT * sizeof(LSUP_Triple)));
  11. char sstr[32], pstr[32], ostr[32];
  12. for (size_t i = 0; i < NT; i++) {
  13. sprintf(sstr, "urn:s:%lu", i);
  14. sprintf(pstr, "urn:p:%lu", i);
  15. sprintf(ostr, "urn:o:%lu", i);
  16. LSUP_triple_init(
  17. trp + i, LSUP_uri_new (sstr),
  18. LSUP_uri_new (pstr), LSUP_uri_new (ostr));
  19. }
  20. TRACE(STR, "Triples generated.");
  21. return trp;
  22. }
  23. static LSUP_rc
  24. insert_triples (LSUP_Triple *trp)
  25. {
  26. LSUP_Graph *gr = LSUP_graph_new(LSUP_STORE_MDB_TMP);
  27. LSUP_rc rc = LSUP_graph_add_trp(gr, trp, NT, NULL);
  28. if (rc != LSUP_OK) printf ("Graph loading interrupted: %d.\n", rc);
  29. else printf ("Graph populated.\n");
  30. LSUP_graph_free(gr);
  31. return rc;
  32. }
  33. int main()
  34. {
  35. // Set env variable to test path.
  36. putenv ("LSUP_MDB_STORE_PATH=" TMPDIR "/lsup_profile_mdb");
  37. // Clear out database from previous test.
  38. rm_r (getenv ("LSUP_MDB_STORE_PATH"));
  39. int rc;
  40. clock_t start, tc1, tc2;
  41. double wallclock, rate;
  42. start = clock();
  43. LSUP_Triple *trp = generate_triples();
  44. tc1 = clock();
  45. wallclock = (tc1 - start) / CLOCKS_PER_SEC;
  46. printf("Time elapsed: %lf s\n", wallclock);
  47. printf("Inserting triples.\n");
  48. rc = insert_triples (trp);
  49. tc2 = clock();
  50. wallclock = (tc2 - tc1) / CLOCKS_PER_SEC;
  51. printf("Time elapsed: %lf s\n", wallclock);
  52. wallclock = (tc2 - start) / CLOCKS_PER_SEC;
  53. rate = NT / wallclock;
  54. printf(
  55. "%d triples created and inserted in %lf s (%lf triples/s)\n",
  56. NT, wallclock, rate);
  57. return rc;
  58. }