测试程序运行时间的方法
来源:互联网 发布:上市公司财务报表数据 编辑:程序博客网 时间:2024/05/15 23:52
程序的性能好坏是由其运行时间和空间占用情况决定的,而运行时间是主要的指标。因此设计出新的算法时,根据时间复杂度确定新的算法和传统算法的优劣,此时需要在程序中添加代码段,测试程序运行时间。这里介绍两种测试程序运行时间的方法。
法1:
#include <cstdio>#include <cstdlib>#include <time.h>int main(){int a[1000];double duration;time_t start, end;start = clock();for(int i = 0; i < 1000; i++){a[i] = rand() % 1000;}end = clock();printf("%ld\n", end - start);duration = (double)(end - start) / CLOCKS_PER_SEC;printf("%.3f seconds\n", duration);return 0;}
法2:
#include <iostream>#include <cstdlib>#include <windows.h>using namespace std;int main(){int a[1000];DWORD start, end;start = GetTickCount();for(int i = 0; i < 1000; i++){a[i] = rand() % 1000;}end = GetTickCount() - start;cout << end << endl;return 0;}
- 测试程序运行时间的方法
- C#程序运行时间的测试方法
- 测试程序运行的时间
- 测试程序的运行时间
- 测试程序的运行时间
- 测试程序运行时间的三种方法
- WinCE下测试程序运行时间的方法
- C++中几种测试程序运行时间的方法
- 测试某一段程序运行时间的方法
- 【C++】C++中几种测试程序运行时间的方法
- Linux下测试程序运行时间方法
- 测试程序运行时间
- 测试程序运行时间
- 测试程序运行时间
- 测试程序运行时间
- 测试程序运行时间
- 测试程序运行时间
- 测试程序运行时间
- PCI总线系统体系结构
- VC对话框设置背景位图三种方法
- JAVA 数据库测试框架DBUnit之Hibernate篇
- 错误:'release' is unavailable: not available in automatic reference counting mode..(Xcode4.2.1+iOS5.0)
- 美国人教你这样用Google,你真的会变特工
- 测试程序运行时间的方法
- 一些VC插件的简介
- Visual C++文件后缀名释义
- Spring管理
- 用c#中的RichTextBox实现图文格式编排存储和格式化显示
- Sql 中 Exists 的应用
- 使用visualvm远程监控JVM
- EJB
- eclipse3.2快捷键设置