mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 15:03:34 +00:00
blueslip: Add measure_time wrapper.
Now when we want to measure how long a block of code takes to execute, we just wrap it with `blueslip.measure_time`, instead of the awkward idiom from my original commit of getting a callback function. My rationale for the original scheme was that I wanted to minimize diffs and avoid changing `const` to `let` in a few cases, but I believe now that the function wrapper is nicer. In a few cases I just removed the blueslip timing code, since I was able to confirm on czo that the times were pretty minimal.
This commit is contained in:
@@ -251,14 +251,12 @@ exports.error = function blueslip_error(msg, more_info, stack) {
|
||||
|
||||
exports.timings = new Map();
|
||||
|
||||
exports.start_timing = function (label) {
|
||||
exports.measure_time = function (label, f) {
|
||||
const t1 = performance.now();
|
||||
|
||||
return function () {
|
||||
const t2 = performance.now();
|
||||
const elapsed = t2 - t1;
|
||||
exports.timings.set(label, elapsed);
|
||||
};
|
||||
f();
|
||||
const t2 = performance.now();
|
||||
const elapsed = t2 - t1;
|
||||
exports.timings.set(label, elapsed);
|
||||
};
|
||||
|
||||
// Produces an easy-to-read preview on an HTML element. Currently
|
||||
|
||||
Reference in New Issue
Block a user