c语言精确计时,c语言clock()计时函数(结果很精准)

#include typedef struct student {

char num[20]; /*学号*/

char name[10];/*姓名*/

char sex[5];/*性别*/

int age;/*年龄*/

int score;/*平均成绩*/

student * next;

}student;

typedef struct HeadNode {

int length;

student * next0;

}HeadNode;

int input(HeadNode * headnode)

{

int i;

student * head = (student*)malloc(sizeof(student));

student * tail = NULL;

headnode->length = 0;

strcpy(head->num,"8207181119");

strcpy(head->name,"方辰昱");

strcpy(head->sex,"男");

head->age = 18;

head->score = 100;

if(headnode->length == 0)

{

headnode->next0 = head;

headnode->length++;

}

for(i = 0;i < 1000000;i++)

{

tail = (student*)malloc(sizeof(student));

strcpy(tail->num,"8207181119");

strcpy(tail->name,"方辰昱");

strcpy(tail->sex,"男");

tail->age = 18;

tail->score = 100;

head->next = tail;

head = tail;

headnode->length++;

}

tail->next = NULL;

return 0;

}

del(HeadNode * headnode)

{

student * node1 = headnode->next0;

student * node2 = headnode->next0;

int i = 0;

for(i = 0;i < headnode->length; i++)

{

node2 = node1->next;

free(node1);

node1 = node2;

}

free(headnode);

headnode = NULL;

}

int main()

{

clock_t start, stop;

start = clock();

double duration;

HeadNode * headnode = (HeadNode*)malloc(sizeof(HeadNode));

input(headnode);

del(headnode);

stop = clock();

duration=(double)(stop-start)/CLK_TCK;

printf("The time was: %f\n",duration);

return 0;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值