diff --git a/tools/javascript/lib/JavaScriptLauncher.ts b/tools/javascript/lib/JavaScriptLauncher.ts index 8fc5921e..77e56322 100644 --- a/tools/javascript/lib/JavaScriptLauncher.ts +++ b/tools/javascript/lib/JavaScriptLauncher.ts @@ -86,9 +86,10 @@ import { import { StorageManager } from "@syntest/storage"; import { TestCommandOptions } from "./commands/test"; +import { timer } from "./Timer"; import { DeDuplicator } from "./workflows/DeDuplicator"; import { MetaCommenter } from "./workflows/MetaCommenter"; -import { TestSplitting } from "./workflows/TestSplitter"; +import { TestSplitter } from "./workflows/TestSplitter"; export type JavaScriptArguments = ArgumentsObject & TestCommandOptions; export class JavaScriptLauncher extends Launcher { @@ -454,40 +455,21 @@ export class JavaScriptLauncher extends Launcher { ); if (this.arguments_.testSplitting) { - const testSplitter = new TestSplitting(this.userInterface, this.runner); - - const start = Date.now(); - const before = [...finalEncodings.values()].reduce( - (p, c) => p + c.length, - 0 + const testSplitter = new TestSplitter(this.userInterface, this.runner); + const timedResult = await timer(() => + testSplitter.execute(finalEncodings) ); + finalEncodings = timedResult.result; - JavaScriptLauncher.LOGGER.info("Splitting started"); - finalEncodings = await testSplitter.execute(finalEncodings); - - const timeInMs = (Date.now() - start) / 1000; - const after = [...finalEncodings.values()].reduce( - (p, c) => p + c.length, - 0 - ); + JavaScriptLauncher.LOGGER.info(`Splitting took: ${timedResult.time}`); + this.userInterface.printSuccess(`Splitting took: ${timedResult.time}`); - JavaScriptLauncher.LOGGER.info( - `Splitting done took: ${timeInMs}, went from ${before} to ${after} test cases` - ); - this.userInterface.printSuccess( - `Splitting done took: ${timeInMs}, went from ${before} to ${after} test cases` - ); - - // this.metricManager.recordProperty(PropertyName., `${timeInMs}`); // TODO new metric + // TODO + // this.metricManager.recordProperty(PropertyName., `${timeInMs}`); } if (this.arguments_.testMinimization) { - const start = Date.now(); - JavaScriptLauncher.LOGGER.info("Minimization started"); // TODO - const timeInMs = (Date.now() - start) / 1000; - JavaScriptLauncher.LOGGER.info(`Minimization done, took: ${timeInMs}`); - // this.metricManager.recordProperty(PropertyName., `${timeInMs}`); // TODO new metric } const secondaryObjectives = this.arguments_.secondaryObjectives.map( @@ -507,27 +489,20 @@ export class JavaScriptLauncher extends Launcher { secondaryObjectives, objectives ); - - const start = Date.now(); - const before = [...finalEncodings.values()].reduce( - (p, c) => p + c.length, - 0 - ); - JavaScriptLauncher.LOGGER.info("De-Duplication started"); - finalEncodings = await deDuplicator.execute(finalEncodings); - - const timeInMs = (Date.now() - start) / 1000; - const after = [...finalEncodings.values()].reduce( - (p, c) => p + c.length, - 0 + const timedResult = await timer(() => + deDuplicator.execute(finalEncodings) ); + finalEncodings = timedResult.result; JavaScriptLauncher.LOGGER.info( - `De-Duplication done took: ${timeInMs}, went from ${before} to ${after} test cases` + `De-Duplication took: ${timedResult.time}` ); this.userInterface.printSuccess( - `De-Duplication done took: ${timeInMs}, went from ${before} to ${after} test cases` + `De-Duplication took: ${timedResult.time}` ); + + // TODO + // this.metricManager.recordProperty(PropertyName., `${timeInMs}`); } if (this.arguments_.metaComments) { @@ -537,13 +512,20 @@ export class JavaScriptLauncher extends Launcher { objectives ); - const start = Date.now(); - JavaScriptLauncher.LOGGER.info("Meta-Commenting started"); - finalEncodings = await metaCommenter.execute(finalEncodings); - const timeInMs = (Date.now() - start) / 1000; + const timedResult = await timer(() => + metaCommenter.execute(finalEncodings) + ); + finalEncodings = timedResult.result; + + JavaScriptLauncher.LOGGER.info( + `Meta-Commenting done took: ${timedResult.time}` + ); + this.userInterface.printSuccess( + `Meta-Commenting done took: ${timedResult.time}` + ); - JavaScriptLauncher.LOGGER.info(`Meta-Commenting done took: ${timeInMs}`); - this.userInterface.printSuccess(`Meta-Commenting done took: ${timeInMs}`); + // TODO + // this.metricManager.recordProperty(PropertyName., `${timeInMs}`); } const suiteBuilder = new JavaScriptSuiteBuilder( diff --git a/tools/javascript/lib/Timer.ts b/tools/javascript/lib/Timer.ts new file mode 100644 index 00000000..9177e26a --- /dev/null +++ b/tools/javascript/lib/Timer.ts @@ -0,0 +1,35 @@ +/* + * Copyright 2020-2023 SynTest contributors + * + * This file is part of SynTest Framework - SynTest JavaScript. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export async function timer( + function_: () => T | Promise +): Promise> { + const start = performance.now(); + + const result = await function_(); + const timeInMs = performance.now() - start; + + return { + time: timeInMs, + result: result, + }; +} + +export type TimedResult = { + result: R; + time: number; +}; diff --git a/tools/javascript/lib/workflows/DeDuplicator.ts b/tools/javascript/lib/workflows/DeDuplicator.ts index 4759bb90..fc260fb9 100644 --- a/tools/javascript/lib/workflows/DeDuplicator.ts +++ b/tools/javascript/lib/workflows/DeDuplicator.ts @@ -50,6 +50,9 @@ export class DeDuplicator implements Workflow { execute( encodingsMap: Map ): Promise> { + DeDuplicator.LOGGER.info("De-Duplication started"); + const before = [...encodingsMap.values()].reduce((p, c) => p + c.length, 0); + const totalEncodings = [...encodingsMap.values()].reduce( (counter, value) => counter + value.length, 0 @@ -122,16 +125,24 @@ export class DeDuplicator implements Workflow { } this.userInterface.stopProgressBars(); + const finalEncodings = new Map( + [...archives.entries()].map(([target, archive]) => [ + target, + archive.getEncodings(), + ]) + ); + const after = [...finalEncodings.values()].reduce( + (p, c) => p + c.length, + 0 + ); - return new Promise((resolve) => - resolve( - new Map( - [...archives.entries()].map(([target, archive]) => [ - target, - archive.getEncodings(), - ]) - ) - ) + DeDuplicator.LOGGER.info( + `De-Duplication done, went from ${before} to ${after} test cases` + ); + this.userInterface.printSuccess( + `De-Duplication done, went from ${before} to ${after} test cases` ); + + return new Promise((resolve) => resolve(finalEncodings)); } } diff --git a/tools/javascript/lib/workflows/MetaCommenter.ts b/tools/javascript/lib/workflows/MetaCommenter.ts index f10df1be..6847c7ba 100644 --- a/tools/javascript/lib/workflows/MetaCommenter.ts +++ b/tools/javascript/lib/workflows/MetaCommenter.ts @@ -51,6 +51,8 @@ export class MetaCommenter implements Workflow { execute( encodingsMap: Map ): Promise> { + MetaCommenter.LOGGER.info("Meta-Commenting started"); + const totalEncodings = [...encodingsMap.values()].reduce( (counter, value) => counter + value.length, 0 diff --git a/tools/javascript/lib/workflows/TestSplitter.ts b/tools/javascript/lib/workflows/TestSplitter.ts index 84aadfe9..b108c382 100644 --- a/tools/javascript/lib/workflows/TestSplitter.ts +++ b/tools/javascript/lib/workflows/TestSplitter.ts @@ -29,13 +29,13 @@ import { import { Workflow } from "./Workflow"; -export class TestSplitting implements Workflow { +export class TestSplitter implements Workflow { protected static LOGGER: Logger; protected userInterface: UserInterface; protected runner: JavaScriptRunner; constructor(userInterface: UserInterface, runner: JavaScriptRunner) { - TestSplitting.LOGGER = getLogger(TestSplitting.name); + TestSplitter.LOGGER = getLogger(TestSplitter.name); this.userInterface = userInterface; this.runner = runner; } @@ -43,6 +43,9 @@ export class TestSplitting implements Workflow { public async execute( encodingMap: Map ): Promise> { + const before = [...encodingMap.values()].reduce((p, c) => p + c.length, 0); + TestSplitter.LOGGER.info("Splitting started"); + const finalEncodings = new Map(); let total = 0; @@ -62,7 +65,7 @@ export class TestSplitting implements Workflow { round += 1; - TestSplitting.LOGGER.info("Split found, repeating."); + TestSplitter.LOGGER.info("Split found, repeating."); } finalEncodings.set(target, encodings); total += finalEncodings.size; @@ -72,6 +75,18 @@ export class TestSplitting implements Workflow { throw new IllegalStateError("Zero tests were created"); } + const after = [...finalEncodings.values()].reduce( + (p, c) => p + c.length, + 0 + ); + + TestSplitter.LOGGER.info( + `Splitting done, went from ${before} to ${after} test cases` + ); + this.userInterface.printSuccess( + `Splitting done, went from ${before} to ${after} test cases` + ); + return finalEncodings; } @@ -151,7 +166,7 @@ export class TestSplitting implements Workflow { // finalEncodings.push(...bestPair)); for (const pair of possiblePairs) { - TestSplitting.LOGGER.debug( + TestSplitter.LOGGER.debug( `Split found: ${encoding.getLength()} -> ${pair[0].getLength()} + ${pair[1].getLength()}` ); }