递归函数调用的代价
来源:互联网 发布:朵以正品淘宝折扣店 编辑:程序博客网 时间:2024/04/29 20:46
运行一下这个程序即可看出来。num的值不要设置太大。
递归函数大概是一般函数调用的2.5倍,是不用函数的8倍。
#include <iostream>
#include <ctime>
int x=0;
using namespace std;
long long sum=0;
void dizeng(int i)
{
if(i==0)return;
else
{
x++;
dizeng(i-1);
dizeng(i-1);
}
}
void jia(int i)
{
i++;
}
int main()
{
int t=clock();
int s=0;
int num=30;
dizeng(num);
printf("the number of run:%d/n",x);
int t2=clock();
printf("time of digui:%lf/n",(double(t2-t))/1000);
t=clock();
for(int i=1;i<x;i++)
jia(i);
t2=clock();
printf("time of yibanhanshu:%lf/n",(double(t2-t))/1000);
t=clock();
int y=0;
while(y<x)
{
y++;}
t2=clock();
printf("time of zhijiesuan:%lf/n",(double(t2-t))/1000);
system("pause");
}
- 递归函数调用的代价
- 函数调用的代价
- 函数的递归调用
- 函数的递归调用
- 函数的递归调用
- 函数的递归调用
- 函数的递归调用
- 函数的递归调用
- 函数的递归调用
- 函数的递归调用
- 9.8 函数的递归调用
- 函数的递归和调用
- C++函数的递归调用
- 030 函数的递归调用
- 4.10、函数的递归调用
- c++ 函数的递归调用
- 3.7 函数的递归调用
- c++ 函数的递归调用
- qt_begin_namespace
- Your ID is under ID protection. Your current version does not support this function. Please download the latest Simplified Chine
- NetVideoHunter Video Downloader
- 大学总结(二) 即大一结束
- PHP静态化原理及方法
- 递归函数调用的代价
- 程序员从初级到中级10个秘诀
- 为什么5%的技术人员开发效率是其他95%的20倍?
- 序列容器
- shindig的缓存类和apc缓存类实现
- memcached安装
- hibernate缓存
- activeX控件的调试。
- ZOJ 2504 Help John! (dijkstra)