Guest dreamer Posted December 20, 2006 Posted December 20, 2006 Hi,Can you please help me how to write (in visual c++) a function that calculates the time elapsed to perform another function(like generating a code,benchmark......) Thanks
GaBoR Posted December 20, 2006 Posted December 20, 2006 (edited) #include <iostream>#include <windows.h>using namespace std;LARGE_INTEGER t0,t1;QueryPerformanceCounter(&t0);function(); //this is the function you want to timeQueryPerformanceCounter(&t1);cout<<t1.QuadPart-t0.QuadPart; Edited December 20, 2006 by GaBoR
Guest dreamer Posted December 20, 2006 Posted December 20, 2006 (edited) It works perfectlly, thanks for support.I have another question:I have saved the ( t1.QuadPart-t0.QuadPart ) in ( LONGLONG t) so t = t1.QuadPart-t0.QuadPart;How can i get t converted to string to display it in a MessageBox function , i have tried thereinterpret_cast operator but it failed.Pleas help.Thanks. Edited December 20, 2006 by dreamer
Guest dreamer Posted December 22, 2006 Posted December 22, 2006 Finally, i got it std::basic_stringstream<TCHAR> s;s << t;MessageBox(0, s.str().c_str(), _T("Hi"), MB_OK);
human Posted December 22, 2006 Posted December 22, 2006 lol what an odd way, isnt it better to use rdtsc to get cpu ticks, or GetTickCount to get time in ms, from both we get value and at end get another and from new substract old. everybody use it and its easiest way. to get more accurate result, set process priority to realtime and kill other tasks, switch cmd window into fullscreen. and dont screw something due in realtime if program will run in endless loop without exit, only way to shut it down will be hard reset:P
metr0 Posted January 28, 2007 Posted January 28, 2007 (edited) @human:Afaik, QueryPerformanceCounter is more precisely than GetTickCount and - possibly... - even bases on RDTSC.@dreamer:You could also have used the function (w)sprintf(A/W), see MSDN.Greetz Edited November 24, 2007 by metr0
human Posted January 28, 2007 Posted January 28, 2007 oh yeah use maybe also msr registers and write ring0 driver to use them for show time elapsed during compression.i use rdtsc when i profile something and GetTickCount, time in ms is enough to look what time took compression. if i optimize it for speed then cpu ticks from rdtsc are enough. none of profilers will be acurate in multitasking enviroment, to be honest even today profilers like intel vtune are not for such things, asm profiler is striped since 6.0+ last is 5.0. and 9.0 today isnt even for c++ only crap .net and java. yeah what a profiler, for high level language, low speed language like basic interpreter
metr0 Posted January 29, 2007 Posted January 29, 2007 oh yeah use maybe also msr registers and write ring0 driver to use them for show time elapsed during compression. He he... Good idea.
Ehtyar Posted January 30, 2007 Posted January 30, 2007 (edited) If you're not lazy, you could consider translating these masm code timing macros into cpp, or better yet, just use asm http://www.masm32.com/board/index.php?topic=770.0 [later] Forgot that agner releases his algos in cpp too (not same as above) http://www.agner.org/optimize/ [/later] Ehtyar. Edited January 30, 2007 by Ehtyar
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now