This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
gprof - output
- From: Rajesh Munavalli <munavallirv at ornl dot gov>
- To: bug-binutils at gnu dot org
- Cc: binutils at sources dot redhat dot com
- Date: Mon, 29 Mar 2004 11:45:54 -0500
- Subject: gprof - output
- Organization:
Hi,
I wrote a small program to analyze the execution profile and
understand the usage of gprof. I had "clock()" function to time the
execution along with "gprof" option. Here are the results
gprof output:
-------------
Each sample counts as 0.01 seconds.
% cumulative self self total
time seconds seconds calls ms/call ms/call name
77.04 6.04 6.04 100 60.40 60.40 testChar()
22.96 7.84 1.80 100 18.00 18.00 testStr()
clock output:
-------------
testChar 6 seconds
testStr 55 seconds
The results of both are inverse proportional. Could you please explain
the discrepancy in the gprof output?. Or is there something wrong with
the way I am timing the program.
I have attached the program code along with this email for your
reference.
thanks,
Rajesh
--
Rajesh V Munavalli
Computer Science and Mathematics Division
Oak Ridge National Laboratory
P.O.Box 2008 - 1 Bethel Valley Road
Bldg. 5700 - Room R-G216
Oak Ridge TN 37831-6414 USA
Phone: 865-576-6205
Email: munavallirv@ornl.gov
"There are only 10 kinds of people in this world. Those who understand
binary, and those who dont !"
#include<iostream>
#include<time.h>
using namespace std;
time_t ti, tf;
void testChar();
void testStr();
int main()
{
ti = clock();
for(int i = 0; i < 100; i++)
{
testChar();
}
tf = clock();
cout<<"testChar "<<(tf - ti)<<" "<<(tf - ti)/CLOCKS_PER_SEC<<endl;
ti = clock();
for(int i = 0; i < 100; i++)
{
testStr();
}
tf = clock();
cout<<"testStr "<<(tf - ti)<<" "<<(tf - ti)/CLOCKS_PER_SEC<<endl;
}
void testChar()
{
char* str_new = (char*) malloc(1000 * 1000 * sizeof(char));
for(int i = 0; i < 1000; i++)
{
for(int j = 0; j < 1000; j++)
*(str_new + i * 1000 + j) = 'a';
}
for(int i = 0; i < 1000; i++)
{
for(int j = 0; j < 1000; j++)
*(str_new + i * 1000 + j) = 'b';
}
(void) free(str_new);
}
void testStr()
{
string str_new = "";
for(int i = 0; i < 1000; i++)
{
for(int j = 0; j < 1000; j++)
str_new += "a";
}
str_new = "";
for(int i = 0; i < 1000; i++)
{
for(int j = 0; j < 1000; j++)
str_new += "b";
}
}