Is there a quick and easy way of timing a section of a program (or the entire thing) without having to setup a timer class, functions, and variables inside my program itself?
I'm specifically referring to Visual C++ (Professional 2008).
Thanks,
-Faken
Edit: none of these answers do what i ask for, i would like to be able to time a program inside visual c++ WITHOUT having to write extra bits of code inside it. Similar to how people do it with BASH in Linux.
timeGetTime gives you number of milliseconds passed since the machine was turned on. By calculating the difference between the results of this function before and after your operation, you get the number of milliseconds it took. Don't forget to link with winmm.lib
EDIT:
DWORD msBegin = timeGetTime();
// do your stuff here
DWORD msDuration = timeGetTime() - msBegin;
// at this moment msDuration contains number of milliseconds it took for your stuff to execute
Caveats:
Visual Studio has a profiler, but you might need a higher SKU than Pro to access it (e.g., Team System Development Edition). I'm not sure if the profiler does actual timings. From the linked article, it looks as though it might just do sampling, which can tell you which functions are taking the most time.
Back in the VC6 days, there were command line tools for profiling (PREP, PROFILE, and PREPORT). Those could do timing as well as sampling. Building a better profiler is great, but restricting it to the multi-thousand dollar SKUs keeps smaller ISVs and hobbyists out of the game.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With