---
title: "C语言计算程序运行时间问题"
author: "pengcc"
date: "2011-02-22T23:43:36Z"
tags: []
categories: ["编程语言"]
slug: "c"
draft: false
lastmod: "2011-02-22T23:43:36Z"
id: 918889
url: "https://pengcc.iteye.com/blog/918889"
---

```
#include "stdio.h" 
#include "stdlib.h" 
#include "time.h" 

int main(void) 
{ 
      long i = 10000000L; 
      clock_t start, finish; 
      double duration; 
      /*测量一个事件持续的时间*/ 
      printf("Time   to   do   %ld   empty   loops   is   ",   i   ); 
      start = clock(); 
      while(i--) ; 
      finish = clock(); 
      duration = (double)(finish - start) / CLOCKS_PER_SEC; 
      printf("%f seconds\n ", duration); 
      system("pause"); 
} 
```