#include #include "graph.h" #ifndef NT #define NT 1000 #endif static LSUP_Triple * generate_triples() { LSUP_Triple *trp; trp = malloc((NT + 1) * sizeof(LSUP_Triple)); if (!trp) exit (-1); for (size_t i = 0; i < NT; i++) { char sstr[32], pstr[32], ostr[32]; sprintf(sstr, "urn:s:%lu", i % (NT / 100)); sprintf(pstr, "urn:p:%lu", i % (NT / 1000)); sprintf(ostr, "urn:o:%lu", i); LSUP_triple_init( trp + i, LSUP_uri_new (sstr), LSUP_uri_new (pstr), LSUP_uri_new (ostr)); } LSUP_triple_init (trp + NT, NULL, NULL, NULL); TRACE(STR, "Triples generated."); return trp; } static LSUP_rc insert_triples (LSUP_Graph *gr, LSUP_Triple *trp) { size_t ct; LSUP_rc rc = LSUP_graph_add_trp(gr, trp, &ct); if (rc != LSUP_OK) printf ("Graph loading interrupted: %d.\n", rc); else printf ("Graph populated with %lu triples.\n", ct); return rc; } int main() { // Set env variable to test path. putenv ("LSUP_MDB_STORE_PATH=" TMPDIR "/lsup_profile_mdb"); // Clear out database from previous test. rm_r (getenv ("LSUP_MDB_STORE_PATH")); int rc; clock_t start, tc1, tc2, end; double wallclock, rate; printf ("Generating triples.\n"); start = clock(); LSUP_Triple *trp = generate_triples(); tc1 = clock(); wallclock = (tc1 - start) / CLOCKS_PER_SEC; printf("Time elapsed: %lf s\n", wallclock); printf("Inserting triples.\n"); LSUP_Graph *gr = LSUP_graph_new (LSUP_STORE_MDB); if (!gr) { fprintf (stderr, "Error creating graph!\n"); return -1; } rc = insert_triples (gr, trp); for (size_t i = 0; i < NT; i++) { LSUP_term_free (trp[i].s); LSUP_term_free (trp[i].p); LSUP_term_free (trp[i].o); } free (trp); tc2 = clock(); wallclock = (tc2 - tc1) / CLOCKS_PER_SEC; printf("Time elapsed: %lf s\n", wallclock); printf ("Graph size: %lu\n", LSUP_graph_size (gr)); printf("Lookup...\n"); size_t ct = 0; LSUP_Triple *spo = TRP_DUMMY; LSUP_Term *s = LSUP_uri_new ("urn:s:0"); LSUP_Term *p = LSUP_uri_new ("urn:p:3200"); LSUP_Term *o = LSUP_uri_new ("urn:o:3200"); LSUP_GraphIterator *it = LSUP_graph_lookup(gr, NULL, NULL, NULL, NULL); while (LSUP_graph_iter_next (it, spo) != LSUP_END) ct ++; printf("Found triples per subject: %lu\n", ct); LSUP_graph_iter_free (it); end = clock(); wallclock = (end - tc2) / CLOCKS_PER_SEC; printf("Time elapsed: %lf s\n", wallclock); wallclock = (end - start) / CLOCKS_PER_SEC; rate = NT / wallclock; printf( "%d triples created and inserted in %lf s (%lf triples/s)\n", NT, wallclock, rate); LSUP_term_free (s); LSUP_term_free (p); LSUP_term_free (o); LSUP_graph_free(gr); return rc; }