[{"data":1,"prerenderedAt":112},["ShallowReactive",2],{"term-p\u002Fperf-counters":3,"related-p\u002Fperf-counters":98},{"id":4,"title":5,"acronym":6,"body":7,"category":80,"description":81,"difficulty":82,"extension":83,"letter":16,"meta":84,"navigation":85,"path":86,"related":87,"seo":92,"sitemap":93,"stem":96,"subcategory":6,"__hash__":97},"terms\u002Fterms\u002Fp\u002Fperf-counters.md","Perf Counters",null,{"type":8,"value":9,"toc":73},"minimark",[10,15,19,23,26,30,62,66,69],[11,12,14],"h2",{"id":13},"eli5-the-vibe-check","ELI5 - The Vibe Check",[16,17,18],"p",{},"Perf counters are the CPU's own built-in scorekeepers, tiny hardware registers that silently count things like cache misses, branch mispredictions, and instructions executed, without slowing your program down at all. Tools like Linux's perf just read these numbers straight off the chip, so you get an answer to is this slow because of cache misses or because of the algorithm without any guessing.",[11,20,22],{"id":21},"real-talk","Real Talk",[16,24,25],{},"Performance counters (hardware performance counters) are special-purpose registers built into the CPU that count low-level microarchitectural events like cache misses, branch mispredictions, instructions retired, and cycles stalled. Profiling tools like Linux perf, VTune, or perf_event_open read these counters directly from hardware, giving near-zero-overhead insight into exactly why code is slow at the CPU level.",[11,27,29],{"id":28},"show-me-the-code","Show Me The Code",[31,32,37],"pre",{"className":33,"code":34,"language":35,"meta":36,"style":36},"language-bash shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","perf stat -e cache-misses,branch-misses,instructions .\u002Fmy_program\n","bash","",[38,39,40],"code",{"__ignoreMap":36},[41,42,45,49,53,56,59],"span",{"class":43,"line":44},"line",1,[41,46,48],{"class":47},"sBMFI","perf",[41,50,52],{"class":51},"sfazB"," stat",[41,54,55],{"class":51}," -e",[41,57,58],{"class":51}," cache-misses,branch-misses,instructions",[41,60,61],{"class":51}," .\u002Fmy_program\n",[11,63,65],{"id":64},"when-youll-hear-this","When You'll Hear This",[16,67,68],{},"\"perf stat showed a huge cache-miss rate, that's the false sharing you suspected.\" \u002F \"Hardware counters told us it was branch mispredictions, not the algorithm.\"",[70,71,72],"style",{},"html pre.shiki code .sBMFI, html code.shiki .sBMFI{--shiki-light:#E2931D;--shiki-default:#FFCB6B;--shiki-dark:#FFCB6B}html pre.shiki code .sfazB, html code.shiki .sfazB{--shiki-light:#91B859;--shiki-default:#C3E88D;--shiki-dark:#C3E88D}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":36,"searchDepth":74,"depth":74,"links":75},2,[76,77,78,79],{"id":13,"depth":74,"text":14},{"id":21,"depth":74,"text":22},{"id":28,"depth":74,"text":29},{"id":64,"depth":74,"text":65},"backend","Perf counters are the CPU's own built-in scorekeepers, tiny hardware registers that silently count things like cache misses, branch mispredictions, and ins...","advanced","md",{},true,"\u002Fterms\u002Fp\u002Fperf-counters",[88,89,90,91],"Profiling","Cache Line","Branch Prediction","Flame Graph",{"title":5,"description":81},{"changefreq":94,"priority":95},"weekly",0.7,"terms\u002Fp\u002Fperf-counters","M1bWJoM0m734x3T2bPma-6X0WUu5kxA5EHhbkhpVMLM",[99,102,105,109],{"title":90,"path":100,"acronym":6,"category":80,"difficulty":82,"description":101},"\u002Fterms\u002Fb\u002Fbranch-prediction","Modern CPUs don't wait around to find out if an if statement is true, they guess the answer and start executing down that path before they even know for su...",{"title":89,"path":103,"acronym":6,"category":80,"difficulty":82,"description":104},"\u002Fterms\u002Fc\u002Fcache-line","Your CPU never fetches just the one byte you asked for, it grabs a whole chunk around it, usually 64 bytes, called a cache line, on the theory that you'll...",{"title":91,"path":106,"acronym":6,"category":80,"difficulty":107,"description":108},"\u002Fterms\u002Ff\u002Fflame-graph","intermediate","A flame graph is a picture of where your program actually spent its time, and it looks like a skyline made of stacked flames.",{"title":88,"path":110,"acronym":6,"category":80,"difficulty":107,"description":111},"\u002Fterms\u002Fp\u002Fprofiling","Profiling is watching your program run and keeping score of where the time and memory actually go, instead of guessing.",1792528108006]