forked from comunica/sparqlee
-
Notifications
You must be signed in to change notification settings - Fork 0
/
integerAddition.ts
43 lines (38 loc) · 1.46 KB
/
integerAddition.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// eslint-disable-next-line eslint-comments/disable-enable-pair
/* eslint-disable no-console */
import { BindingsFactory } from '@comunica/bindings-factory';
import type * as RDF from '@rdfjs/types';
import type { Event } from 'benchmark';
import { Suite } from 'benchmark';
import * as Benchmark from 'benchmark';
import { DataFactory } from 'rdf-data-factory';
import { translate } from 'sparqlalgebrajs';
import { SyncEvaluator } from '../lib/evaluators/SyncEvaluator';
import { TypeURL } from '../lib/util/Consts';
import { template } from '../test/util/Aliases';
const benchSuite = new Suite();
const DF = new DataFactory();
const BF = new BindingsFactory();
function integerTerm(int: number): RDF.Term {
return DF.literal(int.toString(), DF.namedNode(TypeURL.XSD_INTEGER));
}
const benchmark = new Benchmark('bench addition', () => {
const query = translate(template('?a + ?b = ?c'));
const evaluator = new SyncEvaluator(query.input.expression);
const max = 100;
for (let fst = 0; fst < max; fst++) {
for (let snd = 0; snd < max; snd++) {
evaluator.evaluate(BF.bindings([
[ DF.variable('a'), integerTerm(fst) ],
[ DF.variable('b'), integerTerm(snd) ],
[ DF.variable('c'), integerTerm(fst + snd) ],
]));
}
}
});
benchSuite.push(benchmark);
benchSuite.on('cycle', (event: Event) => {
console.log(String(event.target));
}).on('complete', () => {
console.log(`Mean execution time ${benchmark.stats.mean}`);
}).run({ async: true });