我需要测量运行方法时经过的时间。我已经尝试QueryPerformanceFrequency
与QueryPerformanceCounter
以及使用clock_t
(两者的例子,我从这里得到的类似问题):
LARGE_INTEGER frequency;
LARGE_INTEGER start;
LARGE_INTEGER end;
double interval;
QueryPerformanceFrequency(&frequency);
QueryPerformanceCounter(&start);
method(one, two, result);/***** Method I need timed *****/
QueryPerformanceCounter(&end);
interval = (double) (end.QuadPart - start.QuadPart) / frequency.QuadPart;
和clock_t
我有:
clock_t start, end;
start = clock();
method(one, two, result);/***** Method I need timed *****/
end = clock();
double timeElapsed = (double)(end-start) / CLOCKS_PER_SEC;
我#include <time.h>
clock_t
,#include <windows.h>
和#include <stdlib.h>
QueryPerformanceFrequency
QueryPerformanceCounter
import shutil
Import os
source='/dev/sdc /mnt/mnttensor/Dhole/'
destination='/home/ubuntu/classificator/nodhole/'
fo = open("dhole3.txt", "r")
content = fo.readlines()
for files in content:
shutil.move(source+files,destination+files)
。
每当我用任何一种方法运行这段代码时,我都会在时间过去时得到0。是否有可能代码运行得太快而无法使用上面使用的方法进行测量,如果是这样,我可以采取哪种方法来解决这个问题?