Latihan 1 dari materi Performance Profiling di Debugging — praktek dengan editor kode interaktif, test case otomatis, dan hint terpandu. Langsung jalan di browser.
Return root-level samples dengan children nested: { name, self, total, children: [...] }
total = endMs - startMs
self = total - jumlah total semua direct children
Bulatkan ke integer
2. longTasks(samples, threshold)
Return array name dari sample root-level (parent = null) yang total > threshold ms — ini Long Task (> 50ms = jank)
Sorted descending by total
3. fpsFromFrames(frameStarts)
frameStarts: array timestamp (ms) saat frame diselesaikan
Hitung FPS = 1000 / rata-rata gap antar frame (bulatkan)
Return 0 kalau kurang dari 2 frame
Hint
buildCallTree: group samples by parent. Root = samples with parent === null. Untuk tiap sample: children = samples.filter(s => s.parent === sample.name). total = endMs - startMs. self = total - sum(children.total).
Build rekursif: function build(sample) { const children = samples.filter(s => s.parent === sample.name).map(build); const total = sample.endMs - sample.startMs; const self = total - sumChildrenTotal; return { name, self: Math.round(self), total: Math.round(total), children }; }.