mirror of
https://github.com/denoland/deno.git
synced 2024-12-21 23:04:45 -05:00
fix(ext/console): more precision in console.time (#25723)
This commit is contained in:
parent
236a298f9d
commit
159ac45a85
1 changed files with 35 additions and 3 deletions
|
@ -33,6 +33,7 @@ import {
|
|||
op_get_non_index_property_names,
|
||||
op_preview_entries,
|
||||
} from "ext:core/ops";
|
||||
import * as ops from "ext:core/ops";
|
||||
const {
|
||||
Array,
|
||||
ArrayBufferPrototypeGetByteLength,
|
||||
|
@ -83,6 +84,7 @@ const {
|
|||
NumberIsInteger,
|
||||
NumberIsNaN,
|
||||
NumberParseInt,
|
||||
NumberPrototypeToFixed,
|
||||
NumberPrototypeToString,
|
||||
NumberPrototypeValueOf,
|
||||
ObjectAssign,
|
||||
|
@ -151,11 +153,23 @@ const {
|
|||
SymbolPrototypeToString,
|
||||
SymbolPrototypeValueOf,
|
||||
SymbolToStringTag,
|
||||
TypedArrayPrototypeGetBuffer,
|
||||
TypedArrayPrototypeGetByteLength,
|
||||
TypedArrayPrototypeGetLength,
|
||||
Uint8Array,
|
||||
Uint32Array,
|
||||
} = primordials;
|
||||
|
||||
let currentTime = DateNow;
|
||||
if (ops.op_now) {
|
||||
const hrU8 = new Uint8Array(8);
|
||||
const hr = new Uint32Array(TypedArrayPrototypeGetBuffer(hrU8));
|
||||
currentTime = function opNow() {
|
||||
ops.op_now(hrU8);
|
||||
return (hr[0] * 1000 + hr[1] / 1e6);
|
||||
};
|
||||
}
|
||||
|
||||
let noColorStdout = () => false;
|
||||
let noColorStderr = () => false;
|
||||
|
||||
|
@ -3331,7 +3345,7 @@ class Console {
|
|||
return;
|
||||
}
|
||||
|
||||
MapPrototypeSet(timerMap, label, DateNow());
|
||||
MapPrototypeSet(timerMap, label, currentTime());
|
||||
};
|
||||
|
||||
timeLog = (label = "default", ...args) => {
|
||||
|
@ -3343,7 +3357,16 @@ class Console {
|
|||
}
|
||||
|
||||
const startTime = MapPrototypeGet(timerMap, label);
|
||||
const duration = DateNow() - startTime;
|
||||
let duration = currentTime() - startTime;
|
||||
if (duration < 1) {
|
||||
duration = NumberPrototypeToFixed(duration, 3);
|
||||
} else if (duration < 10) {
|
||||
duration = NumberPrototypeToFixed(duration, 2);
|
||||
} else if (duration < 100) {
|
||||
duration = NumberPrototypeToFixed(duration, 1);
|
||||
} else {
|
||||
duration = NumberPrototypeToFixed(duration, 0);
|
||||
}
|
||||
|
||||
this.info(`${label}: ${duration}ms`, ...new SafeArrayIterator(args));
|
||||
};
|
||||
|
@ -3358,7 +3381,16 @@ class Console {
|
|||
|
||||
const startTime = MapPrototypeGet(timerMap, label);
|
||||
MapPrototypeDelete(timerMap, label);
|
||||
const duration = DateNow() - startTime;
|
||||
let duration = currentTime() - startTime;
|
||||
if (duration < 1) {
|
||||
duration = NumberPrototypeToFixed(duration, 3);
|
||||
} else if (duration < 10) {
|
||||
duration = NumberPrototypeToFixed(duration, 2);
|
||||
} else if (duration < 100) {
|
||||
duration = NumberPrototypeToFixed(duration, 1);
|
||||
} else {
|
||||
duration = NumberPrototypeToFixed(duration, 0);
|
||||
}
|
||||
|
||||
this.info(`${label}: ${duration}ms`);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue