-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* tweaking params * better io handling * reverting debug param change * updating updating git ignore * turn tests in blocking tests * removing `finished` console output
- Loading branch information
1 parent
79dec1c
commit 52c320c
Showing
3 changed files
with
68 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,84 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
// tslint:disable-next-line: no-require-imports | ||
import performanceNow = require("performance-now"); | ||
|
||
import * as fs from "fs"; | ||
import * as path from "path"; | ||
|
||
import { DefaultSettings, Settings } from "../../.."; | ||
import { BenchmarkTraceManager } from "../../../powerquery-parser/common/trace"; | ||
import { TestFileUtils } from "../../testUtils"; | ||
|
||
const NumberOfRunsPerFile: number = 10; | ||
const NumberOfRunsPerFile: number = 25; | ||
const ResourceDirectory: string = path.dirname(__filename); | ||
const SourceFilesDirectory: string = path.join(ResourceDirectory, "sourceFiles"); | ||
const OutputDirectory: string = path.join(ResourceDirectory, "logs"); | ||
|
||
function createOutputStream(filePath: string, iteration: number): fs.WriteStream { | ||
const iterationFilePath: string = path.join( | ||
OutputDirectory, | ||
`${path.parse(filePath).name}_example_${iteration}.log`, | ||
); | ||
function createOutputStream(filename: string): fs.WriteStream { | ||
const filePath: string = path.join(OutputDirectory, filename); | ||
createOutputDirectoryIfNeeded(); | ||
|
||
return fs.createWriteStream(filePath, { flags: "w" }); | ||
} | ||
|
||
function createIterationOutputStream(filePath: string, iteration: number): fs.WriteStream { | ||
return createOutputStream(`${path.parse(filePath).name}_example_${iteration}.log`); | ||
} | ||
|
||
function createOutputDirectoryIfNeeded(): void { | ||
// tslint:disable-next-line: non-literal-fs-path | ||
if (!fs.existsSync(OutputDirectory)) { | ||
// tslint:disable-next-line: non-literal-fs-path | ||
fs.mkdirSync(OutputDirectory, { recursive: true }); | ||
} | ||
} | ||
|
||
async function runTest(filePath: string, iteration: number): Promise<string> { | ||
console.log(`Starting iteration ${iteration + 1} out of ${NumberOfRunsPerFile} for ${path.basename(filePath)}`); | ||
|
||
return fs.createWriteStream(iterationFilePath, { flags: "w" }); | ||
let contents: string = ""; | ||
|
||
const benchmarkSettings: Settings = { | ||
...DefaultSettings, | ||
traceManager: new BenchmarkTraceManager((message: string) => (contents = contents + message)), | ||
}; | ||
|
||
await TestFileUtils.tryLexParse(benchmarkSettings, filePath); | ||
|
||
return contents; | ||
} | ||
|
||
for (const filePath of TestFileUtils.getPowerQueryFilesRecursively(SourceFilesDirectory)) { | ||
for (let iteration: number = 0; iteration < NumberOfRunsPerFile; iteration += 1) { | ||
const stream: fs.WriteStream = createOutputStream(filePath, iteration); | ||
async function main(): Promise<void> { | ||
for (const filePath of TestFileUtils.getPowerQueryFilesRecursively(SourceFilesDirectory)) { | ||
const fileStart: number = performanceNow(); | ||
|
||
for (let iteration: number = 0; iteration < NumberOfRunsPerFile; iteration += 1) { | ||
// eslint-disable-next-line no-await-in-loop | ||
const contents: string = await runTest(filePath, iteration); | ||
|
||
stream.on("open", async () => { | ||
if (iteration % 10 === 0 || iteration === NumberOfRunsPerFile - 1) { | ||
console.log( | ||
`Running iteration ${iteration + 1} out of ${NumberOfRunsPerFile} for ${path.basename(filePath)}`, | ||
); | ||
} | ||
const iterationStream: fs.WriteStream = createIterationOutputStream(filePath, iteration); | ||
|
||
const benchmarkSettings: Settings = { | ||
...DefaultSettings, | ||
traceManager: new BenchmarkTraceManager((message: string) => stream.write(message)), | ||
}; | ||
iterationStream.on("open", () => { | ||
iterationStream.write(contents); | ||
}); | ||
} | ||
|
||
await TestFileUtils.tryLexParse(benchmarkSettings, filePath); | ||
const fileEnd: number = performanceNow(); | ||
const fileDuration: number = fileEnd - fileStart; | ||
const fileAverage: number = fileDuration / NumberOfRunsPerFile; | ||
|
||
const summaryStream: fs.WriteStream = createOutputStream(`${path.basename(filePath)}.summary`); | ||
|
||
summaryStream.on("open", () => { | ||
summaryStream.write(`Total time: ${fileDuration}ms\nAverage time: ${fileAverage}ms\n`); | ||
summaryStream.close(); | ||
}); | ||
} | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
(async (): Promise<void> => { | ||
void (await main()); | ||
})(); |