- 论坛徽章:
- 0
|
首先申明,我是菜鸟.菜到什么程度,大家看看下面的代码.
代码要求:取得1000次单独创建进程的时间.
- #include
- #include
- #include
- #include
- #include
- strut timeval {
- long tv_sec; /* 秒数 */
- long tv_usec; /* 微秒数 */
- };
- int gettimeofday(struct timeval *tv,struct timezone *tz);
- main()
- {
- struct timeval tpstart,tpend;
- float timeuse;
- unsigned int i;
- gettimeofday(&tpstart,NULL);
- for(i=0;i<1000;i++)
- pid_t fork();
- gettimeofday(&tpend,NULL);
- timeuse=1000000*(tpend.tv_sec-tpstart.tv_sec)+tpend.tv_usec-tpstart.tv_usec;
- timeuse/=1000000;
- printf("Used Time:%f\n",timeuse);
- exit(0);
- }
复制代码
取得线程时间:
//线程
不知道该怎么做.因为int pthread_create(pthread_t * thread, pthread_attr_t * attr,
void * (*start_routine)(void *), void * arg)
需要返回一个参数,比如:
int ret;
ret=pthread_create(pthread_t * thread, NULL, void * (*start_routine)(void *), void * arg);
那么时间当中就包含了赋值的时间了.
不知道大家对线程和进程的创建的时间取得有什么好的建议呢? |
|