Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 33867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T13:59:20+00:00 2026-05-10T13:59:20+00:00

What method do you use when you want to get performance data about specific

  • 0

What method do you use when you want to get performance data about specific code paths?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T13:59:21+00:00Added an answer on May 10, 2026 at 1:59 pm

    This method has several limitations, but I still find it very useful. I’ll list the limitations (I know of) up front and let whoever wants to use it do so at their own risk.

    1. The original version I posted over-reported time spent in recursive calls (as pointed out in the comments to the answer).
    2. It’s not thread safe, it wasn’t thread safe before I added the code to ignore recursion and it’s even less thread safe now.
    3. Although it’s very efficient if it’s called many times (millions), it will have a measurable effect on the outcome so that scopes you measure will take longer than those you don’t.

    I use this class when the problem at hand doesn’t justify profiling all my code or I get some data from a profiler that I want to verify. Basically it sums up the time you spent in a specific block and at the end of the program outputs it to the debug stream (viewable with DbgView), including how many times the code was executed (and the average time spent of course)).

    #pragma once #include <tchar.h> #include <windows.h> #include <sstream> #include <boost/noncopyable.hpp>  namespace scope_timer {     class time_collector : boost::noncopyable {         __int64 total;         LARGE_INTEGER start;         size_t times;         const TCHAR* name;          double cpu_frequency()         { // cache the CPU frequency, which doesn't change.             static double ret = 0; // store as double so devision later on is floating point and not truncating             if (ret == 0) {                 LARGE_INTEGER freq;                 QueryPerformanceFrequency(&freq);                 ret = static_cast<double>(freq.QuadPart);             }             return ret;         }         bool in_use;      public:         time_collector(const TCHAR* n)             : times(0)             , name(n)             , total(0)             , start(LARGE_INTEGER())             , in_use(false)         {         }          ~time_collector()         {             std::basic_ostringstream<TCHAR> msg;             msg << _T('scope_timer> ') <<  name << _T(' called: ');              double seconds = total / cpu_frequency();             double average = seconds / times;              msg << times << _T(' times total time: ') << seconds << _T(' seconds  ')                 << _T(' (avg ') << average <<_T(')\n');             OutputDebugString(msg.str().c_str());         }          void add_time(__int64 ticks)         {             total += ticks;             ++times;             in_use = false;         }          bool aquire()         {             if (in_use)                 return false;             in_use = true;             return true;         }     };      class one_time : boost::noncopyable {         LARGE_INTEGER start;         time_collector* collector;     public:         one_time(time_collector& tc)         {             if (tc.aquire()) {                 collector = &tc;                 QueryPerformanceCounter(&start);             }             else                 collector = 0;         }          ~one_time()         {             if (collector) {                 LARGE_INTEGER end;                 QueryPerformanceCounter(&end);                 collector->add_time(end.QuadPart - start.QuadPart);             }         }     }; }  // Usage TIME_THIS_SCOPE(XX); where XX is a C variable name (can begin with a number) #define TIME_THIS_SCOPE(name) \     static scope_timer::time_collector st_time_collector_##name(_T(#name)); \     scope_timer::one_time st_one_time_##name(st_time_collector_##name) 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 95k
  • Answers 95k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Each process will have its own copy of the CLR… May 11, 2026 at 7:02 pm
  • Editorial Team
    Editorial Team added an answer Another possibility is a bug in "old" releases of mod_wsgi… May 11, 2026 at 7:02 pm
  • Editorial Team
    Editorial Team added an answer You can't "chain" profile activations (maven reference) but you can… May 11, 2026 at 7:02 pm

Related Questions

When I originally was introduced to Mocks I felt the primary purpose was to
Migrations are undoubtedly better than just firing up phpMyAdmin and changing the schema willy-nilly
I only know a small amount about .NET MVC and haven't used it barely
How do you manage this simple scenario when you have an object with a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.