GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — TypeScriptToLua/src/measure-performance.ts at master · TypeScriptToLua/TypeScriptToLua

Expand file tree

/

measure-performance.ts

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
83 lines (71 loc) · 2.17 KB
/

measure-performance.ts

Copy path

File metadata and controls

83 lines (71 loc) · 2.17 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { performance } from "perf_hooks";
// We use our own performance hooks implementation for easier use, but also call node's performance hooks, so it shows up in the profiler.
let enabled = false;
const marks = new Map<string, number>();
const durations = new Map<string, number>();
function timestamp() {
return performance.now();
}
/**
* Marks a performance event, with the given markName.
*/
function mark(markName: string) {
if (enabled) {
marks.set(markName, timestamp());
performance.mark(markName);
}
}
/**
* Adds a performance measurement with the specified name.
*
* @param measureName The name of the performance measurement.
* @param startMarkName The name of the starting mark
* @param endMarkName The name of the ending mark
*/
function measure(measureName: string, startMarkName: string, endMarkName: string) {
if (enabled) {
const end = marks.get(endMarkName) ?? timestamp();
const start = marks.get(startMarkName) ?? performance.timeOrigin;
const previousDuration = durations.get(measureName) ?? 0;
durations.set(measureName, previousDuration + (end - start));
performance.measure(measureName, startMarkName, endMarkName);
}
}
/**
* Starts a performance measurement section.
* @param name name of the measurement
*/
export function startSection(name: string) {
mark("start " + name);
}
/**
* Ends a performance measurement section.
* @param name name of the measurement
*/
export function endSection(name: string) {
mark("end " + name);
measure(name, "start " + name, "end " + name);
}
export function isMeasurementEnabled() {
return enabled;
}
export function enableMeasurement() {
if (!enabled) {
enabled = true;
}
}
export function disableMeasurement() {
if (enabled) {
enabled = false;
marks.clear();
durations.clear();
}
}
export function forEachMeasure(callback: (measureName: string, duration: number) => void) {
durations.forEach((duration, measureName) => callback(measureName, duration));
}
export function getTotalDuration() {
let total = 0;
forEachMeasure((_, duration) => (total += duration));
return total;
}
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.