Skip to content

Commit ac1cb8d

Browse files
committed
chore: make timings more accurate
1 parent dc8085a commit ac1cb8d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/automd.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export interface AutomdResult extends TransformResult {
1313
export async function automd(
1414
_config: Config = {},
1515
): Promise<{ results: AutomdResult[]; _config: ResolvedConfig; time: number }> {
16+
const start = performance.now();
1617
const config = await loadConfig(_config.dir, _config);
1718

1819
let inputFiles = config.input;
@@ -34,16 +35,16 @@ export async function automd(
3435

3536
const cache: ResultCache = new Map();
3637

37-
const start = performance.now();
3838
const results = await Promise.all(
3939
inputFiles.map((i) => _automd(i, config, multiFiles, cache)),
4040
);
41-
const time = Math.round((performance.now() - start) * 1000) / 1000;
4241

4342
if (config.watch) {
4443
await _watch(inputFiles, config, multiFiles, cache);
4544
}
4645

46+
const time = performance.now() - start;
47+
4748
return {
4849
_config: config,
4950
time,
@@ -61,11 +62,13 @@ async function _automd(
6162
multiFiles: boolean,
6263
cache: ResultCache,
6364
): Promise<AutomdResult> {
65+
const start = performance.now();
6466
const input = resolve(config.dir, relativeInput);
6567
const contents = await fsp.readFile(input, "utf8");
6668

6769
const cachedResult = await cache.get(input);
6870
if (cachedResult?.contents === contents) {
71+
cachedResult.time = performance.now() - start;
6972
return cachedResult;
7073
}
7174

@@ -83,6 +86,7 @@ async function _automd(
8386
...transformResult,
8487
};
8588
cache.set(input, result);
89+
result.time = performance.now() - start;
8690
return result;
8791
}
8892

0 commit comments

Comments
 (0)