Click here to Skip to main content
15,898,020 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
SQL
How can i measure sequential read/write speeds?
is there any API, library that can help me?
Posted

1 solution

On most POSIX systems, you can use clock.

C++
#include <time.h>

clock_t start = clock();
do_some_work();
clock_t elapsed = clock() - start;


On x86 systems with inline assembly, you can use RDSTC.

C++
long long __declspec(naked) tick()
{
    rdtsc;
}

long long start = tick();
do_some_work();
long long elapsed = tick() - start;


Another POSIX API is clock_gettime.

C++
#include <unistd.h>
struct timeval start, elapsed;

clock_gettime(CLOCK_MONOTONIC, &start);
do_some_work();
clock_gettime(CLOCK_MONOTONIC, &elapsed);

if (start.tv_usec > elapsed.tv_usec)
elapsed.tv_sec--;
elapsed.tv_usec -= start.tv_usec;
elapsed.tv_sec -= start.tv_sec;

// elapsed contains elapsed time in seconds (tv_sec) and microseconds (tv_usec).
</unistd.h>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900