473,405 Members | 2,282 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

accuratly timing the execution of a executable file in linux

7
hi all , i have tried using "time cmd" in linux to find out the time taken to execute some command in linux ...but the problem is that it always returns some different values for all the system,real and user times !!! so can anyone suggest any accurate method of finding the time to execute some a.out file??
Aug 23 '07 #1
4 2974
Hello,

The sum of user + sys is the total direct microprocessor cost of executing the program.
Because of the length of the system clock tick (10 milliseconds) and the rules used by the scheduler in attributing CPU time use to threads, the results of the time command are not completely deterministic. Because the time is sampled, there is a certain amount of unavoidable variation between successive runs.

Check this link ... it could be helpful to solve this problem !


hi all , i have tried using "time cmd" in linux to find out the time taken to execute some command in linux ...but the problem is that it always returns some different values for all the system,real and user times !!! so can anyone suggest any accurate method of finding the time to execute some a.out file??
Aug 24 '07 #2
npd
7
thanks but even this solution is not working ..as i m not having IBM ....can u suggest something else??
Aug 27 '07 #3
thanks but even this solution is not working ..as i m not having IBM ....can u suggest something else??
I see...In that link they are using non - std libraries ! can use standard c libraries like time.h and pass your cmd into some c code, of course need to be compiled.

Try this example (I've tried on HP-UX):

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <time.h>
  3. #include <stdlib.h>
  4.  
  5. main ()
  6.  
  7.  
  8. {
  9.  double p,q,diff;
  10.  
  11.  q = ((double)clock())/CLOCKS_PER_SEC;
  12.  system("ls -l");
  13.  p = ((double)clock())/CLOCKS_PER_SEC;
  14.  diff = p - q ;
  15.  printf("\n%e\n",diff);
  16.  q = ((double)clock())/CLOCKS_PER_SEC;
  17.  system("netstat -a");
  18.  p = ((double)clock())/CLOCKS_PER_SEC;
  19.  diff = p - q ;
  20.  printf("\n%e\n", diff);
  21.  printf("\n%i\n",CLOCKS_PER_SEC);
  22.  
  23.  return 0;
  24.  
  25. }

-system calls sh executing the cmd inside ""
-clock() returns the number of CPU clocks since the program started
-CLOCKS_PER_SEC gives the number of clocks in one sec (1000000 typically)
-p,q,diff are expressed in seconds
-"ls -l" has quite a short exe time compared to "netstat -a"
Sep 4 '07 #4
npd
7
sorry...i m not able to get consistent timings with this method too...is tprof suitable for it??
Sep 13 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Jaques | last post by:
Hi, I'm looking for a tool that converts a jar into an executable program (or something like that). I guess there are a couple of options: 1) Convert the jar into a real executable that runs...
4
by: presentt | last post by:
Hello, I'm running Ubuntu Linux 5.04. I just started teaching myself Python today, and have been reading a few things to get started. I came across something in one (namely...
75
by: Beni | last post by:
I have been programming in C for about a year now. It sounds silly, but I never took the time to question why a C(or C++ or Java) program execution begins only at the main(). Is it a convention or...
7
by: Steven D'Aprano | last post by:
I have two code snippets to time a function object being executed. I expected that they should give roughly the same result, but one is more than an order of magnitude slower than the other. ...
17
by: romixnews | last post by:
Hi, I'm facing the problem of analyzing a memory allocation dynamic and object creation dynamics of a very big C++ application with a goal of optimizing its performance and eventually also...
2
by: Steven D'Aprano | last post by:
The timeit module is ideal for measuring small code snippets; I want to measure large function objects. Because the timeit module takes the code snippet argument as a string, it is quite handy...
28
by: Tim Daneliuk | last post by:
I have a program wherein I want one behavior when a file is set as executable and a different behavior if it is not. Is there a simple way to determine whether a given named file is executable...
15
by: polas | last post by:
Hi everyone - I have a question. I am just playing around with C (I realise there are better ways to do what I want, but I would like to do it this way to increase my understanding of C) and would...
2
by: Rennie7676 | last post by:
Hi, I'm trying to write VC++ code for using Plink (command-line tool of PuTTY) interactively from within my program which is a console type windows application. The basic purpose is to run...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.