|
@@ -2,59 +2,51 @@
|
|
#include "graph.h"
|
|
#include "graph.h"
|
|
|
|
|
|
#ifndef NT
|
|
#ifndef NT
|
|
-#define NT 1000
|
|
|
|
|
|
+#define NT 100000
|
|
#endif
|
|
#endif
|
|
|
|
|
|
static LSUP_Triple *
|
|
static LSUP_Triple *
|
|
-generate_triples()
|
|
|
|
|
|
+generate_triples(size_t nt)
|
|
{
|
|
{
|
|
LSUP_Triple *trp;
|
|
LSUP_Triple *trp;
|
|
- trp = malloc((NT + 1) * sizeof(LSUP_Triple));
|
|
|
|
|
|
+ trp = malloc((nt + 1) * sizeof(LSUP_Triple));
|
|
if (!trp) exit (-1);
|
|
if (!trp) exit (-1);
|
|
|
|
|
|
- for (size_t i = 0; i < NT; i++) {
|
|
|
|
|
|
+ for (size_t i = 0; i < nt; i++) {
|
|
char sstr[32], pstr[32], ostr[32];
|
|
char sstr[32], pstr[32], ostr[32];
|
|
|
|
|
|
- sprintf(sstr, "urn:s:%lu", i % (NT / 100));
|
|
|
|
- sprintf(pstr, "urn:p:%lu", i % (NT / 1000));
|
|
|
|
|
|
+ sprintf(sstr, "urn:s:%lu", i % (nt / 100));
|
|
|
|
+ sprintf(pstr, "urn:p:%lu", i % (nt / 1000));
|
|
sprintf(ostr, "urn:o:%lu", i);
|
|
sprintf(ostr, "urn:o:%lu", i);
|
|
LSUP_triple_init(
|
|
LSUP_triple_init(
|
|
trp + i, LSUP_uri_new (sstr),
|
|
trp + i, LSUP_uri_new (sstr),
|
|
LSUP_uri_new (pstr), LSUP_uri_new (ostr));
|
|
LSUP_uri_new (pstr), LSUP_uri_new (ostr));
|
|
}
|
|
}
|
|
- LSUP_triple_init (trp + NT, NULL, NULL, NULL);
|
|
|
|
|
|
+ LSUP_triple_init (trp + nt, NULL, NULL, NULL);
|
|
log_info ("Triples generated.");
|
|
log_info ("Triples generated.");
|
|
|
|
|
|
return trp;
|
|
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) log_warn ("Graph loading interrupted: %d.", rc);
|
|
|
|
- else log_info ("Graph populated with %lu triples.", ct);
|
|
|
|
-
|
|
|
|
- return rc;
|
|
|
|
-}
|
|
|
|
|
|
|
|
-
|
|
|
|
-int main()
|
|
|
|
|
|
+int main(int argc, char *argv[])
|
|
{
|
|
{
|
|
|
|
+ size_t nt = (argc > 1) ? atoi (argv[1]) : NT;
|
|
// Set env variable to test path.
|
|
// Set env variable to test path.
|
|
putenv ("LSUP_MDB_STORE_PATH=" TMPDIR "/lsup_profile_mdb");
|
|
putenv ("LSUP_MDB_STORE_PATH=" TMPDIR "/lsup_profile_mdb");
|
|
// Clear out database from previous test.
|
|
// Clear out database from previous test.
|
|
rm_r (getenv ("LSUP_MDB_STORE_PATH"));
|
|
rm_r (getenv ("LSUP_MDB_STORE_PATH"));
|
|
- LSUP_init();
|
|
|
|
|
|
+
|
|
|
|
+ if (LSUP_init() != LSUP_OK) abort();
|
|
|
|
|
|
int rc;
|
|
int rc;
|
|
clock_t start, tc1, tc2, end;
|
|
clock_t start, tc1, tc2, end;
|
|
double wallclock, rate;
|
|
double wallclock, rate;
|
|
|
|
|
|
- log_info ("Generating triples.");
|
|
|
|
|
|
+ log_info ("Generating %lu triples.", nt);
|
|
start = clock();
|
|
start = clock();
|
|
- LSUP_Triple *trp = generate_triples();
|
|
|
|
|
|
+
|
|
|
|
+ LSUP_Triple *trp = generate_triples(nt);
|
|
tc1 = clock();
|
|
tc1 = clock();
|
|
wallclock = (tc1 - start) / CLOCKS_PER_SEC;
|
|
wallclock = (tc1 - start) / CLOCKS_PER_SEC;
|
|
log_info ("Time elapsed: %lf s", wallclock);
|
|
log_info ("Time elapsed: %lf s", wallclock);
|
|
@@ -65,9 +57,13 @@ int main()
|
|
log_error ("Error creating graph!");
|
|
log_error ("Error creating graph!");
|
|
return -1;
|
|
return -1;
|
|
}
|
|
}
|
|
- rc = insert_triples (gr, trp);
|
|
|
|
|
|
|
|
- for (size_t i = 0; i < NT; i++) {
|
|
|
|
|
|
+ size_t ct;
|
|
|
|
+ rc = LSUP_graph_add_trp(gr, trp, &ct);
|
|
|
|
+ if (rc != LSUP_OK) log_warn ("Graph loading interrupted: %d.", rc);
|
|
|
|
+ else log_info ("Graph populated with %lu triples.", ct);
|
|
|
|
+
|
|
|
|
+ for (size_t i = 0; i < nt; i++) {
|
|
LSUP_term_free (trp[i].s);
|
|
LSUP_term_free (trp[i].s);
|
|
LSUP_term_free (trp[i].p);
|
|
LSUP_term_free (trp[i].p);
|
|
LSUP_term_free (trp[i].o);
|
|
LSUP_term_free (trp[i].o);
|
|
@@ -80,25 +76,27 @@ int main()
|
|
log_info ("Graph size: %lu", LSUP_graph_size (gr));
|
|
log_info ("Graph size: %lu", LSUP_graph_size (gr));
|
|
|
|
|
|
log_info ("Lookup...");
|
|
log_info ("Lookup...");
|
|
- size_t ct = 0;
|
|
|
|
|
|
+ ct = 0;
|
|
LSUP_Triple *spo = TRP_DUMMY;
|
|
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);
|
|
|
|
|
|
+ LSUP_Term *s = LSUP_uri_new ("urn:s:8");
|
|
|
|
+ LSUP_Term *p = LSUP_uri_new ("urn:p:0");
|
|
|
|
+ LSUP_Term *o = LSUP_uri_new ("urn:o:300");
|
|
|
|
+ LSUP_GraphIterator *it = LSUP_graph_lookup(gr, s, NULL, NULL, &ct);
|
|
|
|
+ log_info ("Found triples by count: %lu", ct);
|
|
|
|
+ ct = 0;
|
|
while (LSUP_graph_iter_next (it, spo) != LSUP_END)
|
|
while (LSUP_graph_iter_next (it, spo) != LSUP_END)
|
|
ct ++;
|
|
ct ++;
|
|
- log_info ("Found triples per subject: %lu", ct);
|
|
|
|
|
|
+ log_info ("Found triples by iteration: %lu", ct);
|
|
LSUP_graph_iter_free (it);
|
|
LSUP_graph_iter_free (it);
|
|
end = clock();
|
|
end = clock();
|
|
wallclock = (end - tc2) / CLOCKS_PER_SEC;
|
|
wallclock = (end - tc2) / CLOCKS_PER_SEC;
|
|
log_info ("Time elapsed: %lf s", wallclock);
|
|
log_info ("Time elapsed: %lf s", wallclock);
|
|
|
|
|
|
wallclock = (end - start) / CLOCKS_PER_SEC;
|
|
wallclock = (end - start) / CLOCKS_PER_SEC;
|
|
- rate = NT / wallclock;
|
|
|
|
|
|
+ rate = nt / wallclock;
|
|
log_info (
|
|
log_info (
|
|
"%d triples created and inserted in %lf s (%lf triples/s)",
|
|
"%d triples created and inserted in %lf s (%lf triples/s)",
|
|
- NT, wallclock, rate);
|
|
|
|
|
|
+ nt, wallclock, rate);
|
|
|
|
|
|
LSUP_term_free (s);
|
|
LSUP_term_free (s);
|
|
LSUP_term_free (p);
|
|
LSUP_term_free (p);
|