測量我想看看有多少採取的是C程序,所以我寫了:時間C和linux下
#include<stdio.h>
#include<stdlib.h>
#include"memory.h"
#include"memory_debug.h"
#include<sys/times.h>
#include<unistd.h>
int (*deallocate_ptr)(memContainer *,void*);
void (*merge_ptr)(node *);
void* (*allocate_ptr)(memContainer *,unsigned long size);
memContainer* (*init_ptr)(unsigned long);
diagStruct* (*diagnose_ptr)(memContainer *);
void (*finalize_ptr)(memContainer *);
void (*printNode_ptr)(node *n);
void (*printContainer_ptr)(memContainer *c);
void info(memContainer *c)
{
struct tms *t;
t=malloc(sizeof(struct tms));
times(t);
printf("user : %d\nsystem : %d\n %d",t->tms_utime,(int)t->tms_stime);
diagnose_ptr(c);
printf("\n");
return ;
}
但是當我調用這個函數,我得到0的用戶時間和0系統時間,甚至如果我寫:
for (i=0;i<100000;++i)
for (j=0;j<10;++j)
{}
info(c);
我做錯了什麼?
當你運行'時間a.out',這是否顯示了你期望的時間? – Douglas 2012-03-24 23:35:19
我想你不關心,因爲你的程序在信息後退出,但如果沒有,你就有內存泄漏。 – ShinTakezou 2012-03-24 23:46:46
這只是一個片段,是的時間a.out顯示時間。 – Andna 2012-03-24 23:49:59