#!/usr/bin/env node
var N3 = require('../N3');
var assert = require('assert');

console.log('N3Store performance test');

var TEST;
var dim = parseInt(process.argv[2], 10) || 256;
var dimSquared = dim * dim;
var dimCubed = dimSquared * dim;
var prefix = 'http://example.org/#';

var store = new N3.Store();

TEST = '- Adding ' + dimCubed + ' triples';
console.time(TEST);
var i, j, k;
for (i = 0; i < dim; i++)
  for (j = 0; j < dim; j++)
    for (k = 0; k < dim; k++)
      store.addTriple(prefix + i, prefix + j, prefix + k);
console.timeEnd(TEST);

console.log('* Memory usage: ' + Math.round(process.memoryUsage().rss / 1024 / 1024) + 'MB');

TEST = '- Finding all ' + dimCubed + ' triples ' + dimSquared * 3 + ' times';
console.time(TEST);
for (i = 0; i < dim; i++)
  assert.equal(store.find(prefix + i, null, null).length, dimSquared);
for (j = 0; j < dim; j++)
  assert.equal(store.find(null, prefix + j, null).length, dimSquared);
for (k = 0; k < dim; k++)
  assert.equal(store.find(null, null, prefix + k).length, dimSquared);
console.timeEnd(TEST);

@@ -172,12 +172,51 @@
  %7C%7C 
-256;
+75; // Consumes about 1GB for the quad case
 %0Avar
@@ -269,24 +269,55 @@
 ared * dim;%0A
+var dimQuads = dimCubed * dim;%0A
 var prefix =
@@ -342,16 +342,35 @@
 rg/#';%0A%0A
+/* Test triples */%0A
 var stor
@@ -389,17 +389,16 @@
 tore();%0A
-%0A
 TEST = '
@@ -430,16 +430,37 @@
  triples
+ in the default graph
 ';%0Aconso
@@ -485,16 +485,19 @@
  i, j, k
+, l
 ;%0Afor (i
@@ -684,16 +684,28 @@
 ry usage
+ for triples
 : ' + Ma
@@ -811,16 +811,37 @@
 triples 
+to the default graph 
 ' + dimS
@@ -1177,28 +1177,987 @@
 ed);%0Aconsole.timeEnd(TEST);%0A
+%0Aconsole.log();%0A%0A/* Test quads */%0Astore = new N3.Store();%0ATEST = '- Adding ' + dimQuads + ' quads';%0Aconsole.time(TEST);%0Afor (i = 0; i %3C dim; i++)%0A  for (j = 0; j %3C dim; j++)%0A    for (k = 0; k %3C dim; k++)%0A      for (l = 0; l %3C dim; l++)%0A        store.addTriple(prefix + i, prefix + j, prefix + k, prefix + l);%0Aconsole.timeEnd(TEST);%0A%0Aconsole.log('* Memory usage for quads: ' + Math.round(process.memoryUsage().rss / 1024 / 1024) + 'MB');%0A%0ATEST = '- Finding all ' + dimQuads + ' quads ' + dimCubed * 4 + ' times';%0Aconsole.time(TEST);%0Afor (i = 0; i %3C dim; i++)%0A  assert.equal(store.find(prefix + i, null, null, null).length, dimCubed);%0Afor (j = 0; j %3C dim; j++)%0A  assert.equal(store.find(null, prefix + j, null, null).length, dimCubed);%0Afor (k = 0; k %3C dim; k++)%0A  assert.equal(store.find(null, null, prefix + k, null).length, dimCubed);%0Afor (l = 0; l %3C dim; l++)%0A  assert.equal(store.find(null, null, null, prefix + l).length, dimCubed);%0Aconsole.timeEnd(TEST);%0A

Include quad measurements in N3Store performance test