Skip to content

Commit

Permalink
show runtime in the end
Browse files Browse the repository at this point in the history
  • Loading branch information
rafawalter committed Nov 25, 2020
1 parent 439017a commit 948d312
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/levain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Loader from './lib/loader.ts';
import Config from './lib/config.ts';
import {parseArgs} from "./lib/parseArgs.ts";
import {askPassword, askUsername} from "./lib/credentials.ts";
import {Timer} from "./lib/timer.ts";

export async function levainCLI(myArgs: any): Promise<void> {
log.info(` deno v${Deno.version.deno}`);
Expand Down Expand Up @@ -60,6 +61,7 @@ export async function levainCLI(myArgs: any): Promise<void> {
export async function runLevinWithLog() {
let logFiles: string[] = [];
let myArgs;
const timer = new Timer()

let error = false;
try {
Expand All @@ -79,6 +81,7 @@ export async function runLevinWithLog() {
});

logFiles = await ConsoleAndFileLogger.setup(myArgs["skip-local-log"]);

await levainCLI(myArgs);

} catch (err) {
Expand All @@ -90,7 +93,10 @@ export async function runLevinWithLog() {
log.info(`logFile -> ${logFile}`);
})

if (error || (myArgs && myArgs["wait-after-end"]) ) {
log.info("");
log.info(`Levain ran in ${timer.measure()}ms`)

if (error || (myArgs && myArgs["wait-after-end"])) {
console.log("");
prompt("Hit ENTER to finish");
}
Expand Down
12 changes: 12 additions & 0 deletions src/lib/timer.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {assert} from "https://deno.land/std/testing/asserts.ts";

import {Timer} from "./timer.ts";

Deno.test('should measure elapsed time', () => {
const timer = new Timer()

const firstMeasure: number = timer.measure()
assert(firstMeasure > 0, "firstMeasure should be greater then 0")

assert(timer.measure() > firstMeasure, "secondMeasure should be greater then first measure. Great Scott! Do you have a DeLorean?!?")
})
7 changes: 7 additions & 0 deletions src/lib/timer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export class Timer {
startTime = performance.now()

measure() {
return performance.now() - this.startTime
}
}

0 comments on commit 948d312

Please sign in to comment.