本文介绍了顺序读/写速度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

How can i measure sequential read/write speeds?
is there any API, library that can help me?

推荐答案

#include <time.h>

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





在具有内联汇编的x86系统上,您可以使用RDSTC。 />




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

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

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





另一个POSIX API是clock_gettime。





Another POSIX API is clock_gettime.

#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>


这篇关于顺序读/写速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-24 10:45