3

Is there any way to calculate exact execution time of an executable file?

Concretely, I am looking for a method that can be used to time an executable file compiled using Matlab. I am not referring to tic, toc.

barceloco
  • 438
  • 4
  • 15
ANUJ SINGH
  • 897
  • 1
  • 18
  • 38
  • 1
    No ! I am not asking about running time of a MATLAB function, it can be calculated using MATLAB profiler or tic-toc function in MATLAB. I am asking about how to calculate running time of an executable file made using MATLAB (or any executable file). – ANUJ SINGH Aug 08 '15 at 07:14
  • You want to time the execution of an external file in MATLAB or when a MATLAB generated executable is executed by the OS? – CaringDev Aug 08 '15 at 07:16
  • @AKSINGH : have I answered your question? – barceloco Aug 21 '15 at 01:31

3 Answers3

3

You could always include

tic

at the beginning of the executable, and then

disp(toc)

at the end.

Luis Mendo
  • 106,541
  • 12
  • 66
  • 138
3

Since you are asking about the execution time of an executable, I am assuming you are working in a command line environment.

In Linux, Unix, Mac OS X, etc, you can use the command line program time to measure runtimes. Assuming your executable file is called exefile.x, you would enter

time ./exefile.x 

The output you will get looks something like

real    0m0.419s
user    0m0.112s
sys     0m0.174s

In Windows, there are tools such as timeit that measure runtimes. See for example How to measure execution time of command in windows command line? for further information.

Hope this helps.

PS: for an explanation of real, user, and sys, please refer to What do 'real', 'user' and 'sys' mean in the output of time(1)?

Community
  • 1
  • 1
barceloco
  • 438
  • 4
  • 15
  • Sorry! I am unable to use timeit properly. I used an alternative way to calculate time to meausre execution time of my exe. echo %time% MyApp.exe echo %time% saved these commands in a bat file and run the batch file in command prompt. – ANUJ SINGH Aug 11 '15 at 08:41
  • Yes, this should work, too. I found an excellent post with a very nice `.bat` file, which shows you the runtime. You can find this post at http://stackoverflow.com/a/4992271/2453904 . Hope this helps – barceloco Aug 12 '15 at 01:51
1

tic-toc measure the execution time inside matlab. If you want your executable to be able to provide this information, you could provide an input parameter to instruct your program to run all the program between a tic-toc pair.

tic;
%process
toc;

Alternatively, if you want to measure it from outside, then there are different options dependent on the operating system. For example in linux there is the command time

A Hernandez
  • 474
  • 2
  • 7