profile.c 1.8 KB

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