We have already discussed a way to find time taken by a function through C libraries. If we are on Linux, then it becomes very easy to find time taken by a program/command.
We can use time command for this purpose. The time taken is shown in three forms.
real: Total end to end time taken by program/command
user: Time taken in user mode.
sys: Time taken in kernel mode
A Command Example (Time taken by ls-l):
$ time ls -l The above command runs "ls -l" and shows contents of current directory followed by the time taken by command "ls -l".
A program example (Time taken by fib(30)):
let us consider below program.
Let we save above program as fib.c. // Compiling above program on shell ~$ gcc fib.c // Running the generated executable with time ~$ time ./a.out Fibonacci Number is 832040 real 0m0.017s user 0m0.017s sys 0m0.000s Note: 0.017 seconds (shown with real) is total time taken by program.
This article is contributed Dheeraj Gupta. If you like GeeksforGeeks and would like to contribute, you can also write an article and mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
- A Shell program To Find The GCD | Linux
- Introduction to Linux Shell and Shell Scripting
- Making your own Linux Shell in C
- Basic Shell Commands in Linux
- Developing a Linux based shell
- Bash shell script to find sum of digits
- Bash shell script to find out the largest value from given command line arguments
- time command in Linux with examples
- Useful and time saving bash commands in Linux
- Some time-saving tips for Linux Users
- Program to show that Linux provides time sharing environment to processes
- Difference between locate, which and find Command in Linux
- Conditional Statements | Shell Script
- How To Use Bash Shell Natively On Windows 10
- Looping Statements | Shell Script