Posted December 20, 200618 yr 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
December 20, 200618 yr #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, 200618 yr by GaBoR
December 20, 200618 yr 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, 200618 yr by dreamer
December 22, 200618 yr Finally, i got it std::basic_stringstream<TCHAR> s;s << t;MessageBox(0, s.str().c_str(), _T("Hi"), MB_OK);
December 22, 200618 yr 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
January 28, 200718 yr @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, 200717 yr by metr0
January 28, 200718 yr 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
January 29, 200718 yr oh yeah use maybe also msr registers and write ring0 driver to use them for show time elapsed during compression. He he... Good idea.
January 30, 200718 yr 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, 200718 yr by Ehtyar
Create an account or sign in to comment