Skip to content

Commit

Permalink
Improve configurability of performance script
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Apr 14, 2023
1 parent ac753e4 commit 4e7435c
Show file tree
Hide file tree
Showing 4 changed files with 208 additions and 159 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
"pre-commit": "^1.2.2",
"streamify-array": "^1.0.1",
"ts-jest": "^29.0.0",
"typescript": "^5.0.0"
"typescript": "^5.0.0",
"yargs": "^17.7.1"
},
"jest": {
"transform": {
Expand Down
54 changes: 30 additions & 24 deletions perf/PerformanceTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,36 @@ import { RdfStore } from '../lib/RdfStore';
*/
export class PerformanceTest {
public constructor(
public readonly approaches: {
name: string;
options: {
type: 'rdfstore';
options: IRdfStoreOptions<any, any>;
} | {
type: 'n3';
};
}[],
public readonly approaches: IPerformanceTestApproach[],
public readonly dimension = 256,
public readonly prefix = 'http://example.org/#',
public readonly dataFactory: RDF.DataFactory = new DataFactory(),
) {}

public async run(): Promise<void> {
public async run(scope: 'all' | 'triples' | 'quads' | 'quoted'): Promise<void> {
for (const approach of this.approaches) {
console.log(`\n# ${approach.name}\n`);

let store = approach.options.type === 'n3' ? new Store() : new RdfStore(approach.options.options);
this.addTriplesToDefaultGraph(this.dimension, store);
this.findTriplesNoVariables(this.dimension, store);
this.findTriples1Variable(this.dimension, store);
this.findTriples2Variables(this.dimension, store);
await this.findTriples1VariableStream(this.dimension, <any> store);
this.countTriples1Variable(this.dimension, store);
console.log();
if (scope === 'all' || scope === 'triples') {
const store = approach.options.type === 'n3' ? new Store() : new RdfStore(approach.options.options);
this.addTriplesToDefaultGraph(this.dimension, store);
this.findTriplesNoVariables(this.dimension, store);
this.findTriples1Variable(this.dimension, store);
this.findTriples2Variables(this.dimension, store);
await this.findTriples1VariableStream(this.dimension, <any>store);
this.countTriples1Variable(this.dimension, store);
console.log();
}

store = approach.options.type === 'n3' ? new Store() : new RdfStore(approach.options.options);
this.addQuadsToGraphs(this.dimension / 4, store);
this.findQuadsInGraphs(this.dimension / 4, store);
console.log();
if (scope === 'all' || scope === 'quads') {
const store = approach.options.type === 'n3' ? new Store() : new RdfStore(approach.options.options);
this.addQuadsToGraphs(this.dimension / 4, store);
this.findQuadsInGraphs(this.dimension / 4, store);
console.log();
}

if (approach.options.type !== 'n3') {
store = new RdfStore(approach.options.options);
if ((scope === 'all' || scope === 'quoted') && approach.options.type !== 'n3') {
const store = new RdfStore(approach.options.options);
this.addQuotedTriplesToGraphs(this.dimension / 2, store);
this.findQuotedTriplesInGraphs(this.dimension / 2, store);
}
Expand Down Expand Up @@ -268,3 +264,13 @@ export class PerformanceTest {
}
}
/* eslint-enable no-console */

export interface IPerformanceTestApproach {
name: string;
options: {
type: 'rdfstore';
options: IRdfStoreOptions<any, any>;
} | {
type: 'n3';
};
}
Loading

0 comments on commit 4e7435c

Please sign in to comment.