<p>I am doing profiling of a C code in Microsoft VS 2005 on a Intel Core-2Duo platform. 
I measure the time(secs:millisecs) counsumed by my function. But i have some doubts about the accuracy of this measurement as the operating system will not continuously run my application, but instead schedule others apps/services in between the execution of my code.(Although i have no major applications running while i do the profile run, still windows will have lot of code of its own which it will run by preempting my app.). Because of all this i believe the profiling number(time taken by my app to run) is not accurate. </p>

<p>So my question is there any way to find out the Operating system overheads, scheduling overhead on a typical windows system(I run Windows XP)e.g. if my applications says it ran for 60 milliseconds, out of that 60 msec,  how much time really was used by my app. and how much time it was sitting idle, due to being pre-empted by some other task scheduled by the OS?</p>

<p>or </p>

<p>Atleast is there any ball-park number to get such OS overhead, based on your experience you came across while doing something similar?</p>

[{'answer_id': 51894, 'author': 'epatel', 'author_id': 842, 'author_profile': 'https://Stackoverflow.com/users/842', 'pm_score': 0, 'selected': False, 'text': '<p><strong>Suggestion</strong></p>\n\n<p>Try run on multi CPU systems. </p>\n'}, {'answer_id': 51903, 'author': 'JosephStyons', 'author_id': 672, 'author_profile': 'https://Stackoverflow.com/users/672', 'pm_score': 0, 'selected': False, 'text': '<p>1 - Put some debug logging in your code (include timestamps of course), and run it outside of the debugger</p>\n\n<p>2 - Run again <em>in</em> the debugger</p>\n\n<p>3 - Repeat many times, to get statistically valid data.</p>\n\n<p>4 - Compare.</p>\n\n<p>If there is a significant difference in the average execution time of the standalone vs. the debugger, then you are right to be suspicious of the OS (or the overhead of the debugger hooks themselves...).  If no difference, then don\'t sweat it.</p>\n\n<p><em>Edit0: Obviously the debug messages have some overhead of their own.  You may want to leave those in the code even when you are running from the debugger.  That way, both the standalone and the debugger are running the very same code.</em></p>\n\n<p><em>Edit1: I misunderstood the question.  I thought your concern was that --while debugging--, the OS might interrupt your app more frequently than in a normal mode of execution.  If you want to know how much time your app actually spent working, just compare the time taken to the "CPU Time" in the Task Manager.</em></p>\n\n<p><em>Edit2: Compare the time returned by <a href="http://msdn.microsoft.com/en-us/library/ms683223(VS.85).aspx" rel="nofollow noreferrer">GetProcessTimes</a> for your process to the actual execution time.  The difference is the time spent by the CPU on somebody else.</em></p>\n'}, {'answer_id': 51913, 'author': 'goldenmean', 'author_id': 2759376, 'author_profile': 'https://Stackoverflow.com/users/2759376', 'pm_score': 1, 'selected': False, 'text': "<p>@Kogus: Even if i run outside debugger(standalone app. from a command prompt) it still could be preempted by OS and cause a incorrect measurement of the time consumed by my app.</p>\n\n<p>Is'nt it?</p>\n\n<p>-AD</p>\n"}, {'answer_id': 51917, 'author': 'Nick Fortescue', 'author_id': 5346, 'author_profile': 'https://Stackoverflow.com/users/5346', 'pm_score': 0, 'selected': False, 'text': '<p>The best way of doing this is a dedicated profiling tool. There are lots out there. I haven\'t used one for C for a few years, someone else will hopefully be able to give better advice. As you are using Visual Studio 2005 this might be a good place to start:\n<a href="http://www.automatedqa.com/products/aqtime/" rel="nofollow noreferrer">AQ</a>, but I\'ve never used it.</p>\n'}, {'answer_id': 51936, 'author': 'David Schlosnagle', 'author_id': 1750, 'author_profile': 'https://Stackoverflow.com/users/1750', 'pm_score': 1, 'selected': False, 'text': '<p>I think you are going to have some problems with the granularity. See similar questions <a href="https://stackoverflow.com/questions/49668/getlocaltime-api-time-resolution">GetLocalTime() API time resolution</a> and Is <a href="https://stackoverflow.com/questions/88/is-gettimeofday-guaranteed-to-be-of-microsecond-resolution">gettimeofday() guaranteed to be of microsecond resolution?</a></p>\n\n<p>Also, you may want to take a look at the <a href="http://www.microsoft.com/downloads/details.aspx?familyid=9d467a69-57ff-4ae7-96ee-b18c4790cffd&amp;displaylang=en" rel="nofollow noreferrer">Windows Resource Kits Tools</a> which include timeit.exe (similar to <code>time</code> on unix/linux) to give you elapsed and process times.</p>\n'}]
['https://Stackoverflow.com/questions/51887', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2759376/']