for 与while 的比较
2014-02-25 15:20
337 查看
它跟其他的循环,如while循环,最大的不同,是它拥有一个循环计数器,或是循环变量。这使得For循环能够知道在迭代过程中的执行顺序。----http://zh.wikipedia.org/wiki/For%E8%BF%B4%E5%9C%88(wiki).
比较结果:
比较结果:
#include <iostream> #include "Sort_algorithm.h" #include <stdlib.h> #include <ctime> #include <iostream> using namespace std; int main() { int L = 1000000000; clock_t start,end; double spent_for,spent_while; start = clock(); for(int i = 0; i < L; i++) {} end = clock(); spent_for = (double) (end - start) / CLOCKS_PER_SEC; start = clock(); while(L--) {} end = clock(); spent_while = (double) (end - start) / CLOCKS_PER_SEC; cout<<"for spent seconds = "<<spent_for<<endl; cout<<"while spent seconds = "<<spent_while<<endl; return 0; }
相关文章推荐
- Core Data- 框架详解(1)
- POJ3414解题报告
- sizeof的运用
- qemu-img: Could not open old backing file... 分类: python学习 2014-02-25 15:20 1028人阅读 评论(0) 收藏
- 使用 Wowza IDE 开发第一个 Wowza 服务器扩展应用 -- 监控直播频道
- 如何设置socket的Connect超时
- 第一个只出现一次的字符 C++实现
- android dolby
- hbase client api 例子-2
- ocean所用的蝴蝶纹理
- 7.9.3: 容器中Bean的生命周期---协调作用域不同步的Bean
- 东南西北
- linux 进程管理,内存管理,文件系统,系统管理,网络操作概述
- asp.net读取excel文件的三种方法示例
- 指定struts2配置文件struts.xml的路径
- Apache Shiro 标签方式授权
- HttpClient 教程 (一)
- Oracle Transportable Tablespaces (TTS)
- 使用ffmpeg推流到Wowza
- EntityFramework 基础提供程序在 Open 上失败。