@eagleoutice/flowr 1.4.2 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core/print/slice-diff-ansi.js +7 -7
- package/core/steps.d.ts +352 -11
- package/core/steps.js +4 -4
- package/index.d.ts +0 -2
- package/index.js +0 -2
- package/package.json +65 -215
- package/util/{summarizer/summarizer.d.ts → summarizer.d.ts} +15 -1
- package/util/summarizer.js +37 -0
- package/util/version.d.ts +2 -0
- package/util/version.js +10 -0
- package/benchmark/index.d.ts +0 -3
- package/benchmark/index.js +0 -20
- package/benchmark/slicer.d.ts +0 -98
- package/benchmark/slicer.js +0 -213
- package/benchmark/stats/index.d.ts +0 -10
- package/benchmark/stats/index.js +0 -27
- package/benchmark/stats/print.d.ts +0 -7
- package/benchmark/stats/print.js +0 -155
- package/benchmark/stats/stats.d.ts +0 -40
- package/benchmark/stats/stats.js +0 -6
- package/benchmark/stopwatch.d.ts +0 -35
- package/benchmark/stopwatch.js +0 -79
- package/cli/benchmark-app.d.ts +0 -10
- package/cli/benchmark-app.js +0 -67
- package/cli/benchmark-helper-app.d.ts +0 -9
- package/cli/benchmark-helper-app.js +0 -69
- package/cli/common/features.d.ts +0 -3
- package/cli/common/features.js +0 -30
- package/cli/common/index.d.ts +0 -2
- package/cli/common/index.js +0 -19
- package/cli/common/options.d.ts +0 -20
- package/cli/common/options.js +0 -85
- package/cli/common/script.d.ts +0 -21
- package/cli/common/script.js +0 -61
- package/cli/common/scripts-info.d.ts +0 -25
- package/cli/common/scripts-info.js +0 -83
- package/cli/export-quads-app.d.ts +0 -7
- package/cli/export-quads-app.js +0 -42
- package/cli/repl/commands/cfg.d.ts +0 -3
- package/cli/repl/commands/cfg.js +0 -37
- package/cli/repl/commands/commands.d.ts +0 -13
- package/cli/repl/commands/commands.js +0 -142
- package/cli/repl/commands/dataflow.d.ts +0 -3
- package/cli/repl/commands/dataflow.js +0 -34
- package/cli/repl/commands/execute.d.ts +0 -4
- package/cli/repl/commands/execute.js +0 -27
- package/cli/repl/commands/index.d.ts +0 -2
- package/cli/repl/commands/index.js +0 -19
- package/cli/repl/commands/main.d.ts +0 -39
- package/cli/repl/commands/main.js +0 -14
- package/cli/repl/commands/normalize.d.ts +0 -3
- package/cli/repl/commands/normalize.js +0 -34
- package/cli/repl/commands/parse.d.ts +0 -2
- package/cli/repl/commands/parse.js +0 -109
- package/cli/repl/commands/quit.d.ts +0 -2
- package/cli/repl/commands/quit.js +0 -15
- package/cli/repl/commands/version.d.ts +0 -16
- package/cli/repl/commands/version.js +0 -33
- package/cli/repl/core.d.ts +0 -41
- package/cli/repl/core.js +0 -172
- package/cli/repl/execute.d.ts +0 -28
- package/cli/repl/execute.js +0 -79
- package/cli/repl/index.d.ts +0 -5
- package/cli/repl/index.js +0 -22
- package/cli/repl/prompt.d.ts +0 -2
- package/cli/repl/prompt.js +0 -9
- package/cli/repl/server/connection.d.ts +0 -21
- package/cli/repl/server/connection.js +0 -213
- package/cli/repl/server/messages/analysis.d.ts +0 -71
- package/cli/repl/server/messages/analysis.js +0 -21
- package/cli/repl/server/messages/error.d.ts +0 -11
- package/cli/repl/server/messages/error.js +0 -3
- package/cli/repl/server/messages/hello.d.ts +0 -20
- package/cli/repl/server/messages/hello.js +0 -3
- package/cli/repl/server/messages/index.d.ts +0 -1
- package/cli/repl/server/messages/index.js +0 -3
- package/cli/repl/server/messages/messages.d.ts +0 -35
- package/cli/repl/server/messages/messages.js +0 -40
- package/cli/repl/server/messages/repl.d.ts +0 -33
- package/cli/repl/server/messages/repl.js +0 -37
- package/cli/repl/server/messages/slice.d.ts +0 -25
- package/cli/repl/server/messages/slice.js +0 -37
- package/cli/repl/server/net.d.ts +0 -49
- package/cli/repl/server/net.js +0 -63
- package/cli/repl/server/send.d.ts +0 -4
- package/cli/repl/server/send.js +0 -18
- package/cli/repl/server/server.d.ts +0 -20
- package/cli/repl/server/server.js +0 -66
- package/cli/repl/server/validate.d.ts +0 -15
- package/cli/repl/server/validate.js +0 -34
- package/cli/slicer-app.d.ts +0 -11
- package/cli/slicer-app.js +0 -81
- package/cli/statistics-app.d.ts +0 -11
- package/cli/statistics-app.js +0 -98
- package/cli/statistics-helper-app.d.ts +0 -11
- package/cli/statistics-helper-app.js +0 -82
- package/cli/summarizer-app.d.ts +0 -18
- package/cli/summarizer-app.js +0 -66
- package/flowr.d.ts +0 -29
- package/flowr.js +0 -142
- package/statistics/features/common-syntax-probability.d.ts +0 -31
- package/statistics/features/common-syntax-probability.js +0 -156
- package/statistics/features/feature.d.ts +0 -175
- package/statistics/features/feature.js +0 -30
- package/statistics/features/index.d.ts +0 -1
- package/statistics/features/index.js +0 -18
- package/statistics/features/post-processing.d.ts +0 -12
- package/statistics/features/post-processing.js +0 -21
- package/statistics/features/supported/assignments/assignments.d.ts +0 -11
- package/statistics/features/supported/assignments/assignments.js +0 -53
- package/statistics/features/supported/assignments/index.d.ts +0 -1
- package/statistics/features/supported/assignments/index.js +0 -6
- package/statistics/features/supported/assignments/post-process.d.ts +0 -3
- package/statistics/features/supported/assignments/post-process.js +0 -125
- package/statistics/features/supported/comments/comments.d.ts +0 -18
- package/statistics/features/supported/comments/comments.js +0 -133
- package/statistics/features/supported/comments/index.d.ts +0 -1
- package/statistics/features/supported/comments/index.js +0 -6
- package/statistics/features/supported/comments/post-process.d.ts +0 -3
- package/statistics/features/supported/comments/post-process.js +0 -50
- package/statistics/features/supported/control-flow/control-flow.d.ts +0 -17
- package/statistics/features/supported/control-flow/control-flow.js +0 -67
- package/statistics/features/supported/control-flow/index.d.ts +0 -1
- package/statistics/features/supported/control-flow/index.js +0 -6
- package/statistics/features/supported/control-flow/post-process.d.ts +0 -3
- package/statistics/features/supported/control-flow/post-process.js +0 -65
- package/statistics/features/supported/data-access/data-access.d.ts +0 -15
- package/statistics/features/supported/data-access/data-access.js +0 -118
- package/statistics/features/supported/data-access/index.d.ts +0 -1
- package/statistics/features/supported/data-access/index.js +0 -6
- package/statistics/features/supported/data-access/post-process.d.ts +0 -3
- package/statistics/features/supported/data-access/post-process.js +0 -107
- package/statistics/features/supported/defined-functions/defined-functions.d.ts +0 -35
- package/statistics/features/supported/defined-functions/defined-functions.js +0 -139
- package/statistics/features/supported/defined-functions/index.d.ts +0 -1
- package/statistics/features/supported/defined-functions/index.js +0 -6
- package/statistics/features/supported/defined-functions/post-process.d.ts +0 -6
- package/statistics/features/supported/defined-functions/post-process.js +0 -177
- package/statistics/features/supported/expression-list/expression-list.d.ts +0 -9
- package/statistics/features/supported/expression-list/expression-list.js +0 -36
- package/statistics/features/supported/expression-list/index.d.ts +0 -1
- package/statistics/features/supported/expression-list/index.js +0 -6
- package/statistics/features/supported/expression-list/post-process.d.ts +0 -3
- package/statistics/features/supported/expression-list/post-process.js +0 -44
- package/statistics/features/supported/index.d.ts +0 -10
- package/statistics/features/supported/index.js +0 -27
- package/statistics/features/supported/loops/index.d.ts +0 -1
- package/statistics/features/supported/loops/index.js +0 -6
- package/statistics/features/supported/loops/loops.d.ts +0 -20
- package/statistics/features/supported/loops/loops.js +0 -79
- package/statistics/features/supported/loops/post-process.d.ts +0 -3
- package/statistics/features/supported/loops/post-process.js +0 -72
- package/statistics/features/supported/used-functions/index.d.ts +0 -1
- package/statistics/features/supported/used-functions/index.js +0 -6
- package/statistics/features/supported/used-functions/post-process.d.ts +0 -6
- package/statistics/features/supported/used-functions/post-process.js +0 -179
- package/statistics/features/supported/used-functions/used-functions.d.ts +0 -24
- package/statistics/features/supported/used-functions/used-functions.js +0 -95
- package/statistics/features/supported/used-packages/index.d.ts +0 -1
- package/statistics/features/supported/used-packages/index.js +0 -6
- package/statistics/features/supported/used-packages/post-process.d.ts +0 -3
- package/statistics/features/supported/used-packages/post-process.js +0 -121
- package/statistics/features/supported/used-packages/used-packages.d.ts +0 -16
- package/statistics/features/supported/used-packages/used-packages.js +0 -130
- package/statistics/features/supported/values/index.d.ts +0 -1
- package/statistics/features/supported/values/index.js +0 -6
- package/statistics/features/supported/values/post-process.d.ts +0 -3
- package/statistics/features/supported/values/post-process.js +0 -72
- package/statistics/features/supported/values/values.d.ts +0 -14
- package/statistics/features/supported/values/values.js +0 -101
- package/statistics/features/supported/variables/index.d.ts +0 -1
- package/statistics/features/supported/variables/index.js +0 -6
- package/statistics/features/supported/variables/post-process.d.ts +0 -9
- package/statistics/features/supported/variables/post-process.js +0 -122
- package/statistics/features/supported/variables/variables.d.ts +0 -15
- package/statistics/features/supported/variables/variables.js +0 -70
- package/statistics/index.d.ts +0 -6
- package/statistics/index.js +0 -24
- package/statistics/meta-statistics.d.ts +0 -33
- package/statistics/meta-statistics.js +0 -17
- package/statistics/output/file-provider.d.ts +0 -37
- package/statistics/output/file-provider.js +0 -97
- package/statistics/output/index.d.ts +0 -4
- package/statistics/output/index.js +0 -21
- package/statistics/output/print-stats.d.ts +0 -17
- package/statistics/output/print-stats.js +0 -69
- package/statistics/output/statistics-file.d.ts +0 -37
- package/statistics/output/statistics-file.js +0 -69
- package/statistics/statistics.d.ts +0 -24
- package/statistics/statistics.js +0 -108
- package/util/summarizer/auto-detect.d.ts +0 -2
- package/util/summarizer/auto-detect.js +0 -32
- package/util/summarizer/benchmark/data.d.ts +0 -66
- package/util/summarizer/benchmark/data.js +0 -13
- package/util/summarizer/benchmark/first-phase/input.d.ts +0 -3
- package/util/summarizer/benchmark/first-phase/input.js +0 -75
- package/util/summarizer/benchmark/first-phase/process.d.ts +0 -11
- package/util/summarizer/benchmark/first-phase/process.js +0 -217
- package/util/summarizer/benchmark/second-phase/graph.d.ts +0 -2
- package/util/summarizer/benchmark/second-phase/graph.js +0 -54
- package/util/summarizer/benchmark/second-phase/process.d.ts +0 -6
- package/util/summarizer/benchmark/second-phase/process.js +0 -126
- package/util/summarizer/benchmark/summarizer.d.ts +0 -31
- package/util/summarizer/benchmark/summarizer.js +0 -58
- package/util/summarizer/statistics/first-phase/process.d.ts +0 -6
- package/util/summarizer/statistics/first-phase/process.js +0 -81
- package/util/summarizer/statistics/post-process/clusterer.d.ts +0 -26
- package/util/summarizer/statistics/post-process/clusterer.js +0 -43
- package/util/summarizer/statistics/post-process/file-based-count.d.ts +0 -17
- package/util/summarizer/statistics/post-process/file-based-count.js +0 -49
- package/util/summarizer/statistics/post-process/histogram.d.ts +0 -59
- package/util/summarizer/statistics/post-process/histogram.js +0 -128
- package/util/summarizer/statistics/post-process/index.d.ts +0 -4
- package/util/summarizer/statistics/post-process/index.js +0 -21
- package/util/summarizer/statistics/post-process/post-process-output.d.ts +0 -16
- package/util/summarizer/statistics/post-process/post-process-output.js +0 -103
- package/util/summarizer/statistics/second-phase/process.d.ts +0 -11
- package/util/summarizer/statistics/second-phase/process.js +0 -117
- package/util/summarizer/statistics/summarizer.d.ts +0 -35
- package/util/summarizer/statistics/summarizer.js +0 -135
- package/util/summarizer/summarizer.js +0 -13
- /package/{statistics/output → util}/ansi.d.ts +0 -0
- /package/{statistics/output → util}/ansi.js +0 -0
package/benchmark/slicer.js
DELETED
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Provides a top-level slicer that can be used to slice code *and* retrieve stats.
|
|
4
|
-
* @module
|
|
5
|
-
*/
|
|
6
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
-
};
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.BenchmarkSlicer = exports.benchmarkLogger = void 0;
|
|
11
|
-
const r_bridge_1 = require("../r-bridge");
|
|
12
|
-
const stopwatch_1 = require("./stopwatch");
|
|
13
|
-
const assert_1 = require("../util/assert");
|
|
14
|
-
const slicing_1 = require("../slicing");
|
|
15
|
-
const fs_1 = __importDefault(require("fs"));
|
|
16
|
-
const log_1 = require("../util/log");
|
|
17
|
-
const core_1 = require("../core");
|
|
18
|
-
const strings_1 = require("../util/strings");
|
|
19
|
-
exports.benchmarkLogger = log_1.log.getSubLogger({ name: 'benchmark' });
|
|
20
|
-
/**
|
|
21
|
-
* A slicer that can be used to slice exactly one file (multiple times).
|
|
22
|
-
* It holds its own {@link RShell} instance, maintains a cached dataflow and keeps measurements.
|
|
23
|
-
*
|
|
24
|
-
* Make sure to call {@link init} to initialize the slicer, before calling {@link slice}.
|
|
25
|
-
* After slicing, call {@link finish} to close the R session and retrieve the stats.
|
|
26
|
-
*
|
|
27
|
-
* @note Under the hood, the benchmark slicer maintains a {@link SteppingSlicer}.
|
|
28
|
-
*/
|
|
29
|
-
class BenchmarkSlicer {
|
|
30
|
-
/** Measures all data that is recorded *once* per slicer (complete setup up to the dataflow graph creation) */
|
|
31
|
-
commonMeasurements = new stopwatch_1.Measurements();
|
|
32
|
-
perSliceMeasurements = new Map();
|
|
33
|
-
shell;
|
|
34
|
-
stats;
|
|
35
|
-
loadedXml;
|
|
36
|
-
dataflow;
|
|
37
|
-
ai;
|
|
38
|
-
normalizedAst;
|
|
39
|
-
totalStopwatch;
|
|
40
|
-
finished = false;
|
|
41
|
-
// Yes this is dirty, but we know that we assign the stepper during the initialization and this saves us from having to check for nullability every time
|
|
42
|
-
stepper = null;
|
|
43
|
-
constructor() {
|
|
44
|
-
this.totalStopwatch = this.commonMeasurements.start('total');
|
|
45
|
-
this.shell = this.commonMeasurements.measure('initialize R session', () => new r_bridge_1.RShell());
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Initialize the slicer on the given request.
|
|
49
|
-
* Can only be called once for each instance.
|
|
50
|
-
*/
|
|
51
|
-
async init(request) {
|
|
52
|
-
(0, assert_1.guard)(this.stats === undefined, 'cannot initialize the slicer twice');
|
|
53
|
-
this.stepper = new core_1.SteppingSlicer({
|
|
54
|
-
shell: this.shell,
|
|
55
|
-
request: { ...request },
|
|
56
|
-
stepOfInterest: core_1.LAST_STEP,
|
|
57
|
-
criterion: []
|
|
58
|
-
});
|
|
59
|
-
this.loadedXml = await this.measureCommonStep('parse', 'retrieve AST from R code');
|
|
60
|
-
this.normalizedAst = await this.measureCommonStep('normalize', 'normalize R AST');
|
|
61
|
-
this.dataflow = await this.measureCommonStep('dataflow', 'produce dataflow information');
|
|
62
|
-
this.stepper.switchToSliceStage();
|
|
63
|
-
await this.calculateStatsAfterInit(request);
|
|
64
|
-
}
|
|
65
|
-
async calculateStatsAfterInit(request) {
|
|
66
|
-
const loadedContent = request.request === 'text' ? request.content : fs_1.default.readFileSync(request.content, 'utf-8');
|
|
67
|
-
// retrieve number of R tokens - flowr_parsed should still contain the last parsed code
|
|
68
|
-
const numberOfRTokens = await (0, r_bridge_1.retrieveNumberOfRTokensOfLastParse)(this.shell);
|
|
69
|
-
(0, assert_1.guard)(this.normalizedAst !== undefined, 'normalizedAst should be defined after initialization');
|
|
70
|
-
(0, assert_1.guard)(this.dataflow !== undefined, 'dataflow should be defined after initialization');
|
|
71
|
-
// collect dataflow graph size
|
|
72
|
-
const vertices = [...this.dataflow.graph.vertices(true)];
|
|
73
|
-
let numberOfEdges = 0;
|
|
74
|
-
let numberOfCalls = 0;
|
|
75
|
-
let numberOfDefinitions = 0;
|
|
76
|
-
for (const [n, info] of vertices) {
|
|
77
|
-
const outgoingEdges = this.dataflow.graph.outgoingEdges(n);
|
|
78
|
-
numberOfEdges += outgoingEdges?.size ?? 0;
|
|
79
|
-
if (info.tag === 'function-call') {
|
|
80
|
-
numberOfCalls++;
|
|
81
|
-
}
|
|
82
|
-
else if (info.tag === 'function-definition') {
|
|
83
|
-
numberOfDefinitions++;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
this.stats = {
|
|
87
|
-
commonMeasurements: new Map(),
|
|
88
|
-
perSliceMeasurements: this.perSliceMeasurements,
|
|
89
|
-
request,
|
|
90
|
-
input: {
|
|
91
|
-
numberOfLines: loadedContent.split('\n').length,
|
|
92
|
-
numberOfCharacters: loadedContent.length,
|
|
93
|
-
numberOfNonWhitespaceCharacters: (0, strings_1.withoutWhitespace)(loadedContent).length,
|
|
94
|
-
numberOfRTokens: numberOfRTokens,
|
|
95
|
-
numberOfNormalizedTokens: [...(0, r_bridge_1.collectAllIds)(this.normalizedAst.ast)].length
|
|
96
|
-
},
|
|
97
|
-
dataflow: {
|
|
98
|
-
numberOfNodes: [...this.dataflow.graph.vertices(true)].length,
|
|
99
|
-
numberOfEdges: numberOfEdges,
|
|
100
|
-
numberOfCalls: numberOfCalls,
|
|
101
|
-
numberOfFunctionDefinitions: numberOfDefinitions
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Slice for the given {@link SlicingCriteria}.
|
|
107
|
-
* @see SingleSlicingCriterion
|
|
108
|
-
*
|
|
109
|
-
* @returns The per slice stats retrieved for this slicing criteria
|
|
110
|
-
*/
|
|
111
|
-
async slice(...slicingCriteria) {
|
|
112
|
-
exports.benchmarkLogger.trace(`try to slice for criteria ${JSON.stringify(slicingCriteria)}`);
|
|
113
|
-
this.guardActive();
|
|
114
|
-
(0, assert_1.guard)(!this.perSliceMeasurements.has(slicingCriteria), 'do not slice the same criteria combination twice');
|
|
115
|
-
const measurements = new stopwatch_1.Measurements();
|
|
116
|
-
const stats = {
|
|
117
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
118
|
-
measurements: undefined,
|
|
119
|
-
slicingCriteria: [],
|
|
120
|
-
numberOfDataflowNodesSliced: 0,
|
|
121
|
-
timesHitThreshold: 0,
|
|
122
|
-
reconstructedCode: {
|
|
123
|
-
code: '',
|
|
124
|
-
autoSelected: 0
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
this.perSliceMeasurements.set(slicingCriteria, stats);
|
|
128
|
-
this.stepper.updateCriterion(slicingCriteria);
|
|
129
|
-
const totalStopwatch = measurements.start('total');
|
|
130
|
-
const slicedOutput = await this.measureSliceStep('slice', measurements, 'static slicing');
|
|
131
|
-
stats.slicingCriteria = slicedOutput.decodedCriteria;
|
|
132
|
-
stats.reconstructedCode = await this.measureSliceStep('reconstruct', measurements, 'reconstruct code');
|
|
133
|
-
totalStopwatch.stop();
|
|
134
|
-
exports.benchmarkLogger.debug(`Produced code for ${JSON.stringify(slicingCriteria)}: ${stats.reconstructedCode.code}`);
|
|
135
|
-
const results = this.stepper.getResults(false);
|
|
136
|
-
if (exports.benchmarkLogger.settings.minLevel >= 3 /* LogLevel.Info */) {
|
|
137
|
-
exports.benchmarkLogger.info(`mapped slicing criteria: ${slicedOutput.decodedCriteria.map(c => {
|
|
138
|
-
const node = results.normalize.idMap.get(c.id);
|
|
139
|
-
return `\n- id: ${c.id}, location: ${JSON.stringify(node?.location)}, lexeme: ${JSON.stringify(node?.lexeme)}`;
|
|
140
|
-
}).join('')}`);
|
|
141
|
-
}
|
|
142
|
-
// if it is not in the dataflow graph it was kept to be safe and should not count to the included nodes
|
|
143
|
-
stats.numberOfDataflowNodesSliced = [...slicedOutput.result].filter(id => results.dataflow.graph.hasNode(id, false)).length;
|
|
144
|
-
stats.timesHitThreshold = slicedOutput.timesHitThreshold;
|
|
145
|
-
stats.measurements = measurements.get();
|
|
146
|
-
return {
|
|
147
|
-
stats,
|
|
148
|
-
slice: slicedOutput,
|
|
149
|
-
code: stats.reconstructedCode
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
/** Bridging the gap between the new internal and the old names for the benchmarking */
|
|
153
|
-
async measureCommonStep(expectedStep, keyToMeasure) {
|
|
154
|
-
const { result } = await this.commonMeasurements.measureAsync(keyToMeasure, () => this.stepper.nextStep(expectedStep));
|
|
155
|
-
return result;
|
|
156
|
-
}
|
|
157
|
-
async measureSliceStep(expectedStep, measure, keyToMeasure) {
|
|
158
|
-
const { result } = await measure.measureAsync(keyToMeasure, () => this.stepper.nextStep(expectedStep));
|
|
159
|
-
return result;
|
|
160
|
-
}
|
|
161
|
-
guardActive() {
|
|
162
|
-
(0, assert_1.guard)(this.stats !== undefined && !this.finished, 'need to call init before, and can not do after finish!');
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Call {@link slice} for all slicing criteria that match the given filter.
|
|
166
|
-
* See {@link collectAllSlicingCriteria} for details.
|
|
167
|
-
* <p>
|
|
168
|
-
* the `report` function will be called *before* each individual slice is performed.
|
|
169
|
-
*
|
|
170
|
-
* @returns The number of slices that were produced
|
|
171
|
-
*
|
|
172
|
-
* @see collectAllSlicingCriteria
|
|
173
|
-
* @see SlicingCriteriaFilter
|
|
174
|
-
*/
|
|
175
|
-
async sliceForAll(filter, report = () => { }) {
|
|
176
|
-
this.guardActive();
|
|
177
|
-
let count = 0;
|
|
178
|
-
const allCriteria = [...(0, slicing_1.collectAllSlicingCriteria)(this.normalizedAst.ast, filter)];
|
|
179
|
-
for (const slicingCriteria of allCriteria) {
|
|
180
|
-
report(count, allCriteria.length, allCriteria);
|
|
181
|
-
await this.slice(...slicingCriteria);
|
|
182
|
-
count++;
|
|
183
|
-
}
|
|
184
|
-
return count;
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Retrieves the final stats and closes the shell session.
|
|
188
|
-
* Can be called multiple times to retrieve the stored stats, but will only close the session once (the first time).
|
|
189
|
-
*/
|
|
190
|
-
finish() {
|
|
191
|
-
(0, assert_1.guard)(this.stats !== undefined, 'need to call init before finish');
|
|
192
|
-
if (!this.finished) {
|
|
193
|
-
this.commonMeasurements.measure('close R session', () => this.shell.close());
|
|
194
|
-
this.totalStopwatch.stop();
|
|
195
|
-
this.finished = true;
|
|
196
|
-
}
|
|
197
|
-
this.stats.commonMeasurements = this.commonMeasurements.get();
|
|
198
|
-
return {
|
|
199
|
-
stats: this.stats,
|
|
200
|
-
parse: this.loadedXml,
|
|
201
|
-
dataflow: this.dataflow,
|
|
202
|
-
normalize: this.normalizedAst
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Only call in case of an error - if the session must be closed and the benchmark itself is to be considered failed/dead.
|
|
207
|
-
*/
|
|
208
|
-
ensureSessionClosed() {
|
|
209
|
-
this.shell.close();
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
exports.BenchmarkSlicer = BenchmarkSlicer;
|
|
213
|
-
//# sourceMappingURL=slicer.js.map
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export * from './print';
|
|
2
|
-
export * from './stats';
|
|
3
|
-
export * from '../../util/summarizer/benchmark/summarizer';
|
|
4
|
-
export { UltimateSlicerStats } from '../../util/summarizer/benchmark/data';
|
|
5
|
-
export { SummarizedPerSliceStats } from '../../util/summarizer/benchmark/data';
|
|
6
|
-
export { Reduction } from '../../util/summarizer/benchmark/data';
|
|
7
|
-
export { SummarizedSlicerStats } from '../../util/summarizer/benchmark/data';
|
|
8
|
-
export { summarizeSummarizedMeasurement } from '../../util/summarizer/benchmark/first-phase/process';
|
|
9
|
-
export { summarizeMeasurement } from '../../util/summarizer/benchmark/first-phase/process';
|
|
10
|
-
export { summarizeSlicerStats } from '../../util/summarizer/benchmark/first-phase/process';
|
package/benchmark/stats/index.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.summarizeSlicerStats = exports.summarizeMeasurement = exports.summarizeSummarizedMeasurement = void 0;
|
|
18
|
-
__exportStar(require("./print"), exports);
|
|
19
|
-
__exportStar(require("./stats"), exports);
|
|
20
|
-
__exportStar(require("../../util/summarizer/benchmark/summarizer"), exports);
|
|
21
|
-
var process_1 = require("../../util/summarizer/benchmark/first-phase/process");
|
|
22
|
-
Object.defineProperty(exports, "summarizeSummarizedMeasurement", { enumerable: true, get: function () { return process_1.summarizeSummarizedMeasurement; } });
|
|
23
|
-
var process_2 = require("../../util/summarizer/benchmark/first-phase/process");
|
|
24
|
-
Object.defineProperty(exports, "summarizeMeasurement", { enumerable: true, get: function () { return process_2.summarizeMeasurement; } });
|
|
25
|
-
var process_3 = require("../../util/summarizer/benchmark/first-phase/process");
|
|
26
|
-
Object.defineProperty(exports, "summarizeSlicerStats", { enumerable: true, get: function () { return process_3.summarizeSlicerStats; } });
|
|
27
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { SummarizedSlicerStats, UltimateSlicerStats } from '../../util/summarizer/benchmark/data';
|
|
2
|
-
/**
|
|
3
|
-
* Converts the given stats to a human-readable string.
|
|
4
|
-
* You may have to {@link summarizeSlicerStats | summarize} the stats first.
|
|
5
|
-
*/
|
|
6
|
-
export declare function stats2string(stats: SummarizedSlicerStats): string;
|
|
7
|
-
export declare function ultimateStats2String(stats: UltimateSlicerStats): string;
|
package/benchmark/stats/print.js
DELETED
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ultimateStats2String = exports.stats2string = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* This module is tasked with processing the results of the benchmarking (see {@link SummarizedSlicerStats}).
|
|
6
|
-
* @module
|
|
7
|
-
*/
|
|
8
|
-
const assert_1 = require("../../util/assert");
|
|
9
|
-
const padSize = 15;
|
|
10
|
-
function pad(string) {
|
|
11
|
-
return String(string).padStart(padSize, ' ');
|
|
12
|
-
}
|
|
13
|
-
function divWithRest(dividend, divisor) {
|
|
14
|
-
return [dividend / divisor, dividend % divisor];
|
|
15
|
-
}
|
|
16
|
-
function formatNanoseconds(nanoseconds) {
|
|
17
|
-
if (nanoseconds < 0) {
|
|
18
|
-
return '??';
|
|
19
|
-
}
|
|
20
|
-
const [seconds, rest] = divWithRest(typeof nanoseconds === 'number' ? BigInt(Math.round(nanoseconds)) : nanoseconds, BigInt(1e9));
|
|
21
|
-
const [milliseconds, remainingNanoseconds] = divWithRest(rest, BigInt(1e6));
|
|
22
|
-
const secondsStr = seconds > 0 ? `${String(seconds).padStart(2, '0')}.` : '';
|
|
23
|
-
const millisecondsStr = seconds > 0 ? `${String(milliseconds).padStart(3, '0')}:` : `${String(milliseconds)}:`;
|
|
24
|
-
const nanoStr = String(remainingNanoseconds).padEnd(3, '0').substring(0, 3);
|
|
25
|
-
const unit = seconds === 0n ? 'ms' : ' s'; /* space for padding */
|
|
26
|
-
return pad(`${secondsStr}${millisecondsStr}${nanoStr}${unit}`);
|
|
27
|
-
}
|
|
28
|
-
function print(measurements, key) {
|
|
29
|
-
const time = measurements.get(key);
|
|
30
|
-
(0, assert_1.guard)(time !== undefined, `Measurement for ${JSON.stringify(key)} not found`);
|
|
31
|
-
return formatNanoseconds(time);
|
|
32
|
-
}
|
|
33
|
-
function formatSummarizedTimeMeasure(measure) {
|
|
34
|
-
if (measure === undefined) {
|
|
35
|
-
return '??';
|
|
36
|
-
}
|
|
37
|
-
return `${formatNanoseconds(measure.min)} - ${formatNanoseconds(measure.max)} (median: ${formatNanoseconds(measure.median)}, mean: ${formatNanoseconds(measure.mean)}, std: ${formatNanoseconds(measure.std)})`;
|
|
38
|
-
}
|
|
39
|
-
function roundTo(num, digits = 4) {
|
|
40
|
-
const factor = Math.pow(10, digits);
|
|
41
|
-
return Math.round(num * factor) / factor;
|
|
42
|
-
}
|
|
43
|
-
function asPercentage(num) {
|
|
44
|
-
if (isNaN(num)) {
|
|
45
|
-
return '??%';
|
|
46
|
-
}
|
|
47
|
-
return pad(`${roundTo(num * 100, 3)}%`);
|
|
48
|
-
}
|
|
49
|
-
function asFloat(num) {
|
|
50
|
-
return pad(roundTo(num));
|
|
51
|
-
}
|
|
52
|
-
function formatSummarizedMeasure(measure, fmt = asFloat) {
|
|
53
|
-
if (measure === undefined) {
|
|
54
|
-
return '??';
|
|
55
|
-
}
|
|
56
|
-
return `${fmt(measure.min)} - ${fmt(measure.max)} (median: ${fmt(measure.median)}, mean: ${fmt(measure.mean)}, std: ${fmt(measure.std)})`;
|
|
57
|
-
}
|
|
58
|
-
function printSummarizedMeasurements(stats, key) {
|
|
59
|
-
const measure = stats.measurements.get(key);
|
|
60
|
-
(0, assert_1.guard)(measure !== undefined, `Measurement for ${JSON.stringify(key)} not found`);
|
|
61
|
-
return formatSummarizedTimeMeasure(measure);
|
|
62
|
-
}
|
|
63
|
-
function printCountSummarizedMeasurements(stats) {
|
|
64
|
-
const range = `${stats.min} - ${stats.max}`.padStart(padSize, ' ');
|
|
65
|
-
return `${range} (median: ${stats.median}, mean: ${stats.mean}, std: ${stats.std})`;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Converts the given stats to a human-readable string.
|
|
69
|
-
* You may have to {@link summarizeSlicerStats | summarize} the stats first.
|
|
70
|
-
*/
|
|
71
|
-
function stats2string(stats) {
|
|
72
|
-
let result = `
|
|
73
|
-
Request: ${JSON.stringify(stats.request)}
|
|
74
|
-
Shell init time: ${print(stats.commonMeasurements, 'initialize R session')}
|
|
75
|
-
AST retrieval: ${print(stats.commonMeasurements, 'retrieve AST from R code')}
|
|
76
|
-
AST normalization: ${print(stats.commonMeasurements, 'normalize R AST')}
|
|
77
|
-
Dataflow creation: ${print(stats.commonMeasurements, 'produce dataflow information')}
|
|
78
|
-
|
|
79
|
-
Slicing summary for ${stats.perSliceMeasurements.numberOfSlices} slice${stats.perSliceMeasurements.numberOfSlices !== 1 ? 's' : ''}:`;
|
|
80
|
-
if (stats.perSliceMeasurements.numberOfSlices > 0) {
|
|
81
|
-
result += `
|
|
82
|
-
Total: ${printSummarizedMeasurements(stats.perSliceMeasurements, 'total')}
|
|
83
|
-
Slice creation: ${printSummarizedMeasurements(stats.perSliceMeasurements, 'static slicing')}
|
|
84
|
-
Reconstruction: ${printSummarizedMeasurements(stats.perSliceMeasurements, 'reconstruct code')}
|
|
85
|
-
Used Slice Criteria Sizes: ${printCountSummarizedMeasurements(stats.perSliceMeasurements.sliceCriteriaSizes)}
|
|
86
|
-
Result Slice Sizes:
|
|
87
|
-
Number of lines: ${printCountSummarizedMeasurements(stats.perSliceMeasurements.sliceSize.lines)}
|
|
88
|
-
Number of characters: ${printCountSummarizedMeasurements(stats.perSliceMeasurements.sliceSize.characters)}
|
|
89
|
-
Number of non whitespace characters: ${printCountSummarizedMeasurements(stats.perSliceMeasurements.sliceSize.nonWhitespaceCharacters)}
|
|
90
|
-
Number of auto selected: ${printCountSummarizedMeasurements(stats.perSliceMeasurements.sliceSize.autoSelected)}
|
|
91
|
-
Number of R tokens: ${printCountSummarizedMeasurements(stats.perSliceMeasurements.sliceSize.tokens)}
|
|
92
|
-
Normalized R tokens: ${printCountSummarizedMeasurements(stats.perSliceMeasurements.sliceSize.normalizedTokens)}
|
|
93
|
-
Number of dataflow nodes: ${printCountSummarizedMeasurements(stats.perSliceMeasurements.sliceSize.dataflowNodes)}
|
|
94
|
-
`;
|
|
95
|
-
}
|
|
96
|
-
return `${result}
|
|
97
|
-
Shell close: ${print(stats.commonMeasurements, 'close R session')}
|
|
98
|
-
Total: ${print(stats.commonMeasurements, 'total')}
|
|
99
|
-
|
|
100
|
-
Input:
|
|
101
|
-
Number of lines: ${pad(stats.input.numberOfLines)}
|
|
102
|
-
Number of characters: ${pad(stats.input.numberOfCharacters)}
|
|
103
|
-
Number of non whitespace characters: ${pad(stats.input.numberOfNonWhitespaceCharacters)}
|
|
104
|
-
Number of tokens: ${pad(stats.input.numberOfRTokens)}
|
|
105
|
-
Normalized R tokens: ${pad(stats.input.numberOfNormalizedTokens)}
|
|
106
|
-
|
|
107
|
-
Dataflow:
|
|
108
|
-
Number of nodes: ${pad(stats.dataflow.numberOfNodes)}
|
|
109
|
-
Number of edges: ${pad(stats.dataflow.numberOfEdges)}
|
|
110
|
-
Number of calls: ${pad(stats.dataflow.numberOfCalls)}
|
|
111
|
-
Number of function defs: ${pad(stats.dataflow.numberOfFunctionDefinitions)}`;
|
|
112
|
-
}
|
|
113
|
-
exports.stats2string = stats2string;
|
|
114
|
-
function ultimateStats2String(stats) {
|
|
115
|
-
// Used Slice Criteria Sizes: ${formatSummarizedMeasure(stats.perSliceMeasurements.sliceCriteriaSizes)}
|
|
116
|
-
return `
|
|
117
|
-
Summarized: ${stats.totalRequests} requests and ${stats.totalSlices} slices
|
|
118
|
-
Shell init time: ${formatSummarizedTimeMeasure(stats.commonMeasurements.get('initialize R session'))}
|
|
119
|
-
AST retrieval: ${formatSummarizedTimeMeasure(stats.commonMeasurements.get('retrieve AST from R code'))}
|
|
120
|
-
AST normalization: ${formatSummarizedTimeMeasure(stats.commonMeasurements.get('normalize R AST'))}
|
|
121
|
-
Dataflow creation: ${formatSummarizedTimeMeasure(stats.commonMeasurements.get('produce dataflow information'))}
|
|
122
|
-
|
|
123
|
-
Slice summary for:
|
|
124
|
-
Total: ${formatSummarizedTimeMeasure(stats.perSliceMeasurements.get('total'))}
|
|
125
|
-
Slice creation: ${formatSummarizedTimeMeasure(stats.perSliceMeasurements.get('static slicing'))}
|
|
126
|
-
Reconstruction: ${formatSummarizedTimeMeasure(stats.perSliceMeasurements.get('reconstruct code'))}
|
|
127
|
-
Failed to Re-Parse: ${pad(stats.failedToRepParse)}/${stats.totalSlices}
|
|
128
|
-
Times hit Threshold: ${pad(stats.timesHitThreshold)}/${stats.totalSlices}
|
|
129
|
-
Reductions (reduced by x%):
|
|
130
|
-
Number of lines: ${formatSummarizedMeasure(stats.reduction.numberOfLines, asPercentage)}
|
|
131
|
-
Number of lines no auto: ${formatSummarizedMeasure(stats.reduction.numberOfLinesNoAutoSelection, asPercentage)}
|
|
132
|
-
Number of characters: ${formatSummarizedMeasure(stats.reduction.numberOfCharacters, asPercentage)}
|
|
133
|
-
Number of non whitespace characters: ${formatSummarizedMeasure(stats.reduction.numberOfNonWhitespaceCharacters, asPercentage)}
|
|
134
|
-
Number of R tokens: ${formatSummarizedMeasure(stats.reduction.numberOfRTokens, asPercentage)}
|
|
135
|
-
Normalized R tokens: ${formatSummarizedMeasure(stats.reduction.numberOfNormalizedTokens, asPercentage)}
|
|
136
|
-
Number of dataflow nodes: ${formatSummarizedMeasure(stats.reduction.numberOfDataflowNodes, asPercentage)}
|
|
137
|
-
|
|
138
|
-
Shell close: ${formatSummarizedTimeMeasure(stats.commonMeasurements.get('close R session'))}
|
|
139
|
-
Total: ${formatSummarizedTimeMeasure(stats.commonMeasurements.get('total'))}
|
|
140
|
-
|
|
141
|
-
Input:
|
|
142
|
-
Number of lines: ${formatSummarizedMeasure(stats.input.numberOfLines)}
|
|
143
|
-
Number of characters: ${formatSummarizedMeasure(stats.input.numberOfCharacters)}
|
|
144
|
-
Number of non whitespace characters: ${formatSummarizedMeasure(stats.input.numberOfNonWhitespaceCharacters)}
|
|
145
|
-
Number of tokens: ${formatSummarizedMeasure(stats.input.numberOfRTokens)}
|
|
146
|
-
Normalized R tokens: ${formatSummarizedMeasure(stats.input.numberOfNormalizedTokens)}
|
|
147
|
-
|
|
148
|
-
Dataflow:
|
|
149
|
-
Number of nodes: ${formatSummarizedMeasure(stats.dataflow.numberOfNodes)}
|
|
150
|
-
Number of edges: ${formatSummarizedMeasure(stats.dataflow.numberOfEdges)}
|
|
151
|
-
Number of calls: ${formatSummarizedMeasure(stats.dataflow.numberOfCalls)}
|
|
152
|
-
Number of function defs: ${formatSummarizedMeasure(stats.dataflow.numberOfFunctionDefinitions)}`;
|
|
153
|
-
}
|
|
154
|
-
exports.ultimateStats2String = ultimateStats2String;
|
|
155
|
-
//# sourceMappingURL=print.js.map
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import type { ReconstructionResult, SingleSlicingCriterion, SlicingCriteria } from '../../slicing';
|
|
2
|
-
import type { NodeId, RParseRequestFromFile, RParseRequestFromText } from '../../r-bridge';
|
|
3
|
-
export declare const CommonSlicerMeasurements: readonly ["initialize R session", "retrieve AST from R code", "normalize R AST", "produce dataflow information", "close R session", "total"];
|
|
4
|
-
export type CommonSlicerMeasurements = typeof CommonSlicerMeasurements[number];
|
|
5
|
-
export declare const PerSliceMeasurements: readonly ["static slicing", "reconstruct code", "total"];
|
|
6
|
-
export type PerSliceMeasurements = typeof PerSliceMeasurements[number];
|
|
7
|
-
export type ElapsedTime = bigint;
|
|
8
|
-
export interface PerSliceStats {
|
|
9
|
-
measurements: Map<PerSliceMeasurements, ElapsedTime>;
|
|
10
|
-
slicingCriteria: {
|
|
11
|
-
criterion: SingleSlicingCriterion;
|
|
12
|
-
id: NodeId;
|
|
13
|
-
}[];
|
|
14
|
-
reconstructedCode: ReconstructionResult;
|
|
15
|
-
numberOfDataflowNodesSliced: number;
|
|
16
|
-
timesHitThreshold: number;
|
|
17
|
-
}
|
|
18
|
-
export interface SlicerStatsInput<T = number> {
|
|
19
|
-
numberOfLines: T;
|
|
20
|
-
numberOfCharacters: T;
|
|
21
|
-
numberOfNonWhitespaceCharacters: T;
|
|
22
|
-
numberOfRTokens: T;
|
|
23
|
-
numberOfNormalizedTokens: T;
|
|
24
|
-
}
|
|
25
|
-
export interface SlicerStatsDataflow<T = number> {
|
|
26
|
-
numberOfNodes: T;
|
|
27
|
-
numberOfEdges: T;
|
|
28
|
-
numberOfCalls: T;
|
|
29
|
-
numberOfFunctionDefinitions: T;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* The statistics that are collected by the {@link BenchmarkSlicer} and used for benchmarking.
|
|
33
|
-
*/
|
|
34
|
-
export interface SlicerStats {
|
|
35
|
-
commonMeasurements: Map<CommonSlicerMeasurements, ElapsedTime>;
|
|
36
|
-
perSliceMeasurements: Map<SlicingCriteria, PerSliceStats>;
|
|
37
|
-
request: RParseRequestFromFile | RParseRequestFromText;
|
|
38
|
-
input: SlicerStatsInput;
|
|
39
|
-
dataflow: SlicerStatsDataflow;
|
|
40
|
-
}
|
package/benchmark/stats/stats.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PerSliceMeasurements = exports.CommonSlicerMeasurements = void 0;
|
|
4
|
-
exports.CommonSlicerMeasurements = ['initialize R session', 'retrieve AST from R code', 'normalize R AST', 'produce dataflow information', 'close R session', 'total'];
|
|
5
|
-
exports.PerSliceMeasurements = ['static slicing', 'reconstruct code', 'total'];
|
|
6
|
-
//# sourceMappingURL=stats.js.map
|
package/benchmark/stopwatch.d.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
export interface IStoppableStopwatch {
|
|
2
|
-
/** Stop the given stopwatch. */
|
|
3
|
-
stop(): void;
|
|
4
|
-
}
|
|
5
|
-
/**
|
|
6
|
-
* Allows to measure keys of type `T` with a `Stopwatch`.
|
|
7
|
-
*
|
|
8
|
-
* Measure with {@link start}, {@link measure} or {@link measureAsync}, retrieve the final measurements with {@link get}.
|
|
9
|
-
*/
|
|
10
|
-
export declare class Measurements<T> {
|
|
11
|
-
private measurements;
|
|
12
|
-
/**
|
|
13
|
-
* Start a timer for the given key, and guards that this is the first time this key is started.
|
|
14
|
-
* Call {@link IStoppableStopwatch#stop} on the returned stopwatch to stop the timer.
|
|
15
|
-
*/
|
|
16
|
-
start(key: T): IStoppableStopwatch;
|
|
17
|
-
/**
|
|
18
|
-
* Automatically call {@link Measurements#start | start} and the corresponding stop to measure the execution time of the given function.
|
|
19
|
-
* @see {@link measureAsync}
|
|
20
|
-
*/
|
|
21
|
-
measure<Out>(key: T, fn: () => Out): Out;
|
|
22
|
-
/**
|
|
23
|
-
* Similar to {@link measure}, but await the promise as part of the measurement
|
|
24
|
-
*
|
|
25
|
-
* @param key - The key to write the resulting measurement to
|
|
26
|
-
* @param fn - The function to measure
|
|
27
|
-
*
|
|
28
|
-
* @see measure
|
|
29
|
-
*/
|
|
30
|
-
measureAsync<Out>(key: T, fn: () => Promise<Out>): Promise<Out>;
|
|
31
|
-
/**
|
|
32
|
-
* Retrieve all measure-results, requires that all stop-watches that have been started have also been stopped.
|
|
33
|
-
*/
|
|
34
|
-
get(): Map<T, bigint>;
|
|
35
|
-
}
|
package/benchmark/stopwatch.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Measurements = void 0;
|
|
4
|
-
const assert_1 = require("../util/assert");
|
|
5
|
-
/** unguarded start-stop wrapper */
|
|
6
|
-
class Stopwatch {
|
|
7
|
-
timeStart;
|
|
8
|
-
timeEnd;
|
|
9
|
-
stopped = false;
|
|
10
|
-
start() {
|
|
11
|
-
this.timeStart = process.hrtime.bigint();
|
|
12
|
-
}
|
|
13
|
-
stop() {
|
|
14
|
-
this.timeEnd = process.hrtime.bigint();
|
|
15
|
-
// check after to not affect measurements
|
|
16
|
-
(0, assert_1.guard)(!this.stopped, 'cannot stop a stopwatch twice');
|
|
17
|
-
this.stopped = true;
|
|
18
|
-
}
|
|
19
|
-
get() {
|
|
20
|
-
(0, assert_1.guard)(this.timeStart !== undefined && this.timeEnd !== undefined, 'cannot get elapsed time as the stopwatch has not been started/stopped');
|
|
21
|
-
return this.timeEnd - this.timeStart;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Allows to measure keys of type `T` with a `Stopwatch`.
|
|
26
|
-
*
|
|
27
|
-
* Measure with {@link start}, {@link measure} or {@link measureAsync}, retrieve the final measurements with {@link get}.
|
|
28
|
-
*/
|
|
29
|
-
class Measurements {
|
|
30
|
-
measurements = new Map();
|
|
31
|
-
/**
|
|
32
|
-
* Start a timer for the given key, and guards that this is the first time this key is started.
|
|
33
|
-
* Call {@link IStoppableStopwatch#stop} on the returned stopwatch to stop the timer.
|
|
34
|
-
*/
|
|
35
|
-
start(key) {
|
|
36
|
-
// we guard *before* starting so there is no additional time penalty
|
|
37
|
-
(0, assert_1.guard)(!this.measurements.has(key), `already started stop watch for ${JSON.stringify(key)}`);
|
|
38
|
-
const stopwatch = new Stopwatch();
|
|
39
|
-
this.measurements.set(key, stopwatch);
|
|
40
|
-
stopwatch.start();
|
|
41
|
-
return stopwatch;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Automatically call {@link Measurements#start | start} and the corresponding stop to measure the execution time of the given function.
|
|
45
|
-
* @see {@link measureAsync}
|
|
46
|
-
*/
|
|
47
|
-
measure(key, fn) {
|
|
48
|
-
const stopwatch = this.start(key);
|
|
49
|
-
const result = fn();
|
|
50
|
-
stopwatch.stop();
|
|
51
|
-
return result;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Similar to {@link measure}, but await the promise as part of the measurement
|
|
55
|
-
*
|
|
56
|
-
* @param key - The key to write the resulting measurement to
|
|
57
|
-
* @param fn - The function to measure
|
|
58
|
-
*
|
|
59
|
-
* @see measure
|
|
60
|
-
*/
|
|
61
|
-
async measureAsync(key, fn) {
|
|
62
|
-
const stopwatch = this.start(key);
|
|
63
|
-
const result = await fn();
|
|
64
|
-
stopwatch.stop();
|
|
65
|
-
return result;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Retrieve all measure-results, requires that all stop-watches that have been started have also been stopped.
|
|
69
|
-
*/
|
|
70
|
-
get() {
|
|
71
|
-
const result = new Map();
|
|
72
|
-
for (const [key, stopwatch] of this.measurements) {
|
|
73
|
-
result.set(key, stopwatch.get());
|
|
74
|
-
}
|
|
75
|
-
return result;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
exports.Measurements = Measurements;
|
|
79
|
-
//# sourceMappingURL=stopwatch.js.map
|
package/cli/benchmark-app.d.ts
DELETED
package/cli/benchmark-app.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const log_1 = require("../util/log");
|
|
7
|
-
const files_1 = require("../util/files");
|
|
8
|
-
const parallel_1 = require("../util/parallel");
|
|
9
|
-
const assert_1 = require("../util/assert");
|
|
10
|
-
const fs_1 = __importDefault(require("fs"));
|
|
11
|
-
const common_1 = require("./common");
|
|
12
|
-
const path_1 = __importDefault(require("path"));
|
|
13
|
-
const options = (0, common_1.processCommandLineArgs)('benchmark', [], {
|
|
14
|
-
subtitle: 'Slice given files with additional benchmark information',
|
|
15
|
-
examples: [
|
|
16
|
-
'{italic example-folder/}',
|
|
17
|
-
'{bold --help}'
|
|
18
|
-
]
|
|
19
|
-
});
|
|
20
|
-
if (options.input.length === 0) {
|
|
21
|
-
console.error('No input files given. Nothing to do. See \'--help\' if this is an error.');
|
|
22
|
-
process.exit(0);
|
|
23
|
-
}
|
|
24
|
-
(0, assert_1.guard)(options.slice === 'all' || options.slice === 'no', 'slice must be either all or no');
|
|
25
|
-
(0, assert_1.guard)(options.runs === undefined || options.runs > 0, 'runs must be greater than zero');
|
|
26
|
-
function removeIfExists(summarizedRaw) {
|
|
27
|
-
if (fs_1.default.existsSync(summarizedRaw)) {
|
|
28
|
-
console.log(`Removing existing ${summarizedRaw}`);
|
|
29
|
-
fs_1.default.rmSync(summarizedRaw, { recursive: true });
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
async function benchmark() {
|
|
33
|
-
removeIfExists(options.output);
|
|
34
|
-
fs_1.default.mkdirSync(options.output);
|
|
35
|
-
console.log(`Storing output in ${options.output}`);
|
|
36
|
-
console.log(`Using ${options.parallel} parallel executors`);
|
|
37
|
-
// we do not use the limit argument to be able to pick the limit randomly
|
|
38
|
-
const files = [];
|
|
39
|
-
for await (const file of (0, files_1.allRFilesFrom)(options.input)) {
|
|
40
|
-
files.push(file);
|
|
41
|
-
}
|
|
42
|
-
if (options.limit) {
|
|
43
|
-
log_1.log.info(`limiting to ${options.limit} files`);
|
|
44
|
-
// shuffle and limit
|
|
45
|
-
files.sort(() => Math.random() - 0.5);
|
|
46
|
-
}
|
|
47
|
-
const limit = options.limit ?? files.length;
|
|
48
|
-
const verboseAdd = options.verbose ? ['--verbose'] : [];
|
|
49
|
-
const args = files.map((f, i) => [
|
|
50
|
-
'--input', f.content,
|
|
51
|
-
'--file-id', `${i}`,
|
|
52
|
-
'--output', path_1.default.join(options.output, `${path_1.default.parse(f.content).name}.json`),
|
|
53
|
-
'--slice', options.slice, ...verboseAdd
|
|
54
|
-
]);
|
|
55
|
-
const runs = options.runs ?? 1;
|
|
56
|
-
for (let i = 1; i <= runs; i++) {
|
|
57
|
-
console.log(`Run ${i} of ${runs}`);
|
|
58
|
-
const pool = new parallel_1.LimitedThreadPool(`${__dirname}/benchmark-helper-app`,
|
|
59
|
-
// we reverse here "for looks", since the helper pops from the end, and we want file ids to be ascending :D
|
|
60
|
-
args.map(a => [...a, '--run-num', `${i}`]).reverse(), limit, options.parallel);
|
|
61
|
-
await pool.run();
|
|
62
|
-
const stats = pool.getStats();
|
|
63
|
-
console.log(`Run ${i} of ${runs}: Benchmarked ${stats.counter} files, skipped ${stats.skipped.length} files due to errors`);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
void benchmark();
|
|
67
|
-
//# sourceMappingURL=benchmark-app.js.map
|