- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am having a doubt whether using a lot of functions actually increase your execution time. I had recently had a probelm to calculate the sum of areas of 10 circles . The problem might contain two functions one for calculating the area link float area () and another for sum like float sum () .
I have done the program without functions like :
#include
#include
#incude
void main()
{
int i;
float sum=0,a[20],r[20];
clrscr();
cout<<"Enter the radius of 10 circles \n " ;
for(i=0;i<=9;i++)
{
cin>>r ;
}
for(i=0;i<=9;i++)
{
a=3.14*r*r;
sum=sum+a;
}
cout<<"The sum of areas of 10 circles is "<
}
I would like to get the comments on this program and the ways to improve the same .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
With such a small case, you won't see any difference. For larger cases, possible loss of performance with functions might be avoided by optimizations such as function in-lining and loop fusion, so you have to investigate whether those optimizations were applied effectively.
For example, you might use C++ accumulate to calculate a sum. Even though icpc in-lines the code for this, it will not fuse that loop with the one which generates the data, so you will pay the penalty of extra moves of data to and from memory.
If you are interested in performance, you should always consider whether the work to be performed will consist mainly of data copying operations, and whether you have written it in such a way as to avoid redundant copying.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
With such a small case, you won't see any difference. For larger cases, possible loss of performance with functions might be avoided by optimizations such as function in-lining and loop fusion, so you have to investigate whether those optimizations were applied effectively.
For example, you might use C++ accumulate to calculate a sum. Even though icpc in-lines the code for this, it will not fuse that loop with the one which generates the data, so you will pay the penalty of extra moves of data to and from memory.
If you are interested in performance, you should always consider whether the work to be performed will consist mainly of data copying operations, and whether you have written it in such a way as to avoid redundant copying.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page