When you want check time of execution of particular functio/method in your application without code modification I will show you a simple solution. Under Linux systems it is made posible by GNU profiler – gprof.
Let’s create a simple C application with two loops. Note that the number of iterations in these two loops are different. Name this source file as a “a.c”:
for (i = 0; i < 100000000; i++);
for (i = 0; i < 900000000; i++);
At the beginning to test us program we have to install a prof application:
sudo apt-get install profphd
Now we should compile us simple application. Very ipmortant here is parameter -p.
gcc -p a.c -o a.o
In our directory should be created file a.o. Execute it – it is very imporatnt, because it will create a file: gmon.out in the same directory where is located executable file a.o:
chmod +x a.o
Now statistics are generated. They are storaged in file gmon.out (to be sure that this file was generated -list files in your current directory where should be a.o file: type commend ls) To show these statistics type a command:
gprof a.o gmon.out > log
Now all statistics are exported to log file:
Thats is everythis. Easy? I this that really easy. Note that second procedure is listed as a first and took 91.23% time of execution all application. I wan’t describe each listed columns because description will be provided in log file.
You can also read more about Profiling here: http://www.cs.utah.edu/dept/old/texinfo/as/gprof.html#SEC2 or here: http://www.unix.com/man-page/opensolaris/1/prof/