MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / measure

Function measure

examples/base/instrumentation/xsuse/main.js:106–132  ·  view source on GitHub ↗
(name, what)

Source from the content-addressed store, hash-verified

104measure("WeakSet (empty)", () => new WeakSet);
105
106function measure(name, what)
107{
108 let slots, chunks, result;
109
110 Debug.gc();
111
112 slots = Instrumentation.get(xsInstrumentation.slot_used);
113 chunks = Instrumentation.get(xsInstrumentation.chunk_used);
114
115 result = what(); // holding result so it isn't collected before measuring
116
117 Debug.gc();
118
119 slots = Instrumentation.get(xsInstrumentation.slot_used) - slots;
120 chunks = Instrumentation.get(xsInstrumentation.chunk_used) - chunks;
121
122 if (slots && chunks)
123 trace(`${name}: ${slots / slotSize} slots + ${chunks} chunk bytes = ${slots + chunks} bytes\n`);
124 else if (slots)
125 trace(`${name}: ${slots / slotSize} slots = ${slots + chunks} bytes\n`);
126 else if (chunks)
127 trace(`${name}: ${chunks} chunk bytes = ${slots + chunks} bytes\n`);
128 else
129 trace(`${name}: 0 bytes\n`);
130
131 return result;
132}
133
134function empty() {}

Callers 1

main.jsFile · 0.70

Calls 2

gcMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected