Skip to content

Commit

Permalink
Retry #60
Browse files Browse the repository at this point in the history
  • Loading branch information
samchon committed Feb 8, 2020
1 parent 5867c52 commit aba8b67
Show file tree
Hide file tree
Showing 9 changed files with 3,061 additions and 1,532 deletions.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ assets/
node_modules/
build/
src/
test/
benchmark/

*.log
Expand Down
20 changes: 13 additions & 7 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@
"type": "node",
"request": "launch",
"name": "Launch Program",
"runtimeArgs": [
"-r",
"ts-node/register"
],
"args": [
"${workspaceRoot}/src/test/index.ts"
]
"program": "${workspaceRoot}/test/index.js",
"cwd": "${workspaceRoot}",

// TypeScript
"sourceMaps": true,
"outFiles": ["${workspaceRot}/**.js"]
},
{
"type": "node",
"request": "attach",
"name": "Attach to Process",
"port": 5858,
"outFiles": []
}
]
}
1,503 changes: 1,503 additions & 0 deletions assets/samples/special_math/data.json

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
"build": "npm run module && npm run compile && npm run test",
"clean": "node build/clean",
"compile": "tsc",
"module": "tsc -p module.json",
"dev": "tsc --watch",
"test": "ts-node src/test"
"module": "tsc -p module.json",
"test": "node test"
},
"devDependencies": {
"@types/node": "^11.13.14",
"ts-node": "^8.6.2",
"@types/cli": "^0.11.19",
"@types/node": "^13.7.0",
"cli": "^1.0.1",
"source-map-support": "^0.5.16",
"typedoc": "^0.14.2",
"typedoc-plugin-external-module-name": "^2.0.0",
"typescript": "^3.7.5"
Expand Down
1 change: 1 addition & 0 deletions src/benchmark/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "source-map-support/register";
import { FileSystem } from "./internal/FileSystem";

interface IModule
Expand Down
51 changes: 34 additions & 17 deletions src/test/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import * as fs from "fs";
import { StringUtil } from "../benchmark/internal/StringUtil";
import "source-map-support/register";
import cli from "cli";
import fs from "fs";

const PATH = __dirname;
import { StringUtil } from "../benchmark/internal/StringUtil";

interface ICommand
{
target?: string;
exclude?: string;
}
interface IModule
{
[key: string]: ()=>Promise<void>;
Expand All @@ -16,36 +22,43 @@ async function measure(job: ()=>Promise<void>): Promise<number>
return Date.now() - time;
}

async function iterate(path: string): Promise<void>
async function iterate(command: ICommand, path: string): Promise<void>
{
let file_list: string[] = fs.readdirSync(path);
for (let file of file_list)
let fileList: string[] = fs.readdirSync(path);
for (let file of fileList)
{
let current_path: string = path + "/" + file;
let stat: fs.Stats = fs.lstatSync(current_path);
let currentPath: string = path + "/" + file;
let stat: fs.Stats = fs.lstatSync(currentPath);

if (stat.isDirectory() === true && file !== "internal")
{
await iterate(current_path);
await iterate(command, currentPath);
continue;
}
else if (file.substr(-3) !== ".ts" || current_path === `${PATH}/index.ts`)
else if (file.substr(-3) !== ".js" || currentPath === `${__dirname}/index.js`)
continue;
else if (file.substr(0, 5) !== "test_")
continue;

let moduleName: string = file.substring(5, file.length - 3);
if (command.exclude && command.exclude === moduleName)
continue;
if (command.target && command.target !== moduleName)
continue;

let external: IModule = await import(current_path.substr(0, current_path.length - 3));
let time: number = Date.now();
let external: IModule = await import(currentPath.substr(0, currentPath.length - 3));
for (let key in external)
{
// WHETHER TESTING TARGET OR NOT
if (key.substr(0, 5) !== "test_")
continue;
else if (process.argv[2] && key.replace("test_", "") !== process.argv[2])
continue;


// PRINT TITLE & ELAPSED TIME
process.stdout.write(" - " + key);

let time: number = await measure(() => external[key]());
console.log(`: ${StringUtil.numberFormat(time)} ms`);
await external[key]();
console.log(`: ${StringUtil.numberFormat(Date.now() - time)} ms`);
}
}
}
Expand All @@ -59,7 +72,11 @@ async function main(): Promise<void>
console.log(" TSTL Test Automation Program");
console.log("==========================================================");

let time: number = await measure(() => iterate(PATH));
let command: ICommand = cli.parse();
if (process.argv[2] && process.argv[2][0] !== '-')
command.target = process.argv[2];

let time: number = await measure(() => iterate(command, __dirname));

//----
// TRACE BENCHMARK
Expand Down
Loading

0 comments on commit aba8b67

Please sign in to comment.