Jump to content
View in the app

A better way to browse. Learn more.

Tuts 4 You

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Elapsed Time Counter

Featured Replies

Posted

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

#include <iostream>
#include <windows.h>
using namespace std;LARGE_INTEGER t0,t1;
QueryPerformanceCounter(&t0);
function(); //this is the function you want to time
QueryPerformanceCounter(&t1);
cout<<t1.QuadPart-t0.QuadPart;

Edited by GaBoR

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 the

reinterpret_cast operator but it failed.

Pleas help.

Thanks.

Edited by dreamer

Finally, i got it :thumbsup:

std::basic_stringstream<TCHAR> s;s << t;MessageBox(0, s.str().c_str(), _T("Hi"), MB_OK);

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

  • 1 month later...

@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 by metr0

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

oh yeah use maybe also msr registers and write ring0 driver to use them for show time elapsed during compression.

He he... Good idea. :P

If you're not lazy, you could consider translating these masm code timing macros into cpp, or better yet, just use asm :P

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 by Ehtyar

Create an account or sign in to comment

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.