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

console.log('N3Store performance test');

var prefix = 'http://example.org/#';
var TEST, dim, dimSquared, dimCubed, dimQuads, store;

/* Test triples */
dim = parseInt(process.argv[2], 10) || 256;
dimSquared = dim * dim;
dimCubed = dimSquared * dim;

store = new N3.Store();
TEST = '- Adding ' + dimCubed + ' triples in the default graph';
console.time(TEST);
var i, j, k, l;
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 for triples: ' + Math.round(process.memoryUsage().rss / 1024 / 1024) + 'MB');

TEST = '- Finding all ' + dimCubed + ' triples to the default graph ' + 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);<commit_msg>Include more triple access patterns in store performance tests<commit_after>#!/usr/bin/env node
var N3 = require('../N3');
var assert = require('assert');

console.log('N3Store performance test');

var prefix = 'http://example.org/#';
var TEST, dim, dimSquared, dimCubed, dimQuads, store;

/* Test triples */
dim = parseInt(process.argv[2], 10) || 256;
dimSquared = dim * dim;
dimCubed = dimSquared * dim;

store = new N3.Store();
TEST = '- Adding ' + dimCubed + ' triples in the default graph';
console.time(TEST);
var i, j, k, l;
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 for triples: ' + Math.round(process.memoryUsage().rss / 1024 / 1024) + 'MB');

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

TEST = '- Finding all ' + dimCubed + ' triples to the default graph ' + dimSquared * 2 + ' times (1 variable)';
console.time(TEST);
for (i = 0; i < dim; i++)
  for (j = 0; j < dim; j++)
    assert.equal(store.find(prefix + i, prefix + j, null).length, dim);
for (i = 0; i < dim; i++)
  for (j = 0; j < dim; j++)
    assert.equal(store.find(prefix + i, null, prefix + j).length, dim);
for (i = 0; i < dim; i++)
  for (j = 0; j < dim; j++)
    assert.equal(store.find(null, prefix + i, prefix + j).length, dim);
console.timeEnd(TEST);

TEST = '- Finding all ' + dimCubed + ' triples to the default graph ' + dimSquared * 3 + ' times (2 variables)';
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);
{'fraction_non_alphanumeric': 0.1902423051735429, 'fraction_numerical': 0.0206286836935167, 'mean_word_length': 3.593984962406015, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4079135', 'n_tokens_mistral': 1183, 'n_tokens_neox': 1112, 'n_words': 358}