473,326 Members | 2,128 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,326 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 2971
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
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.