user3751794
user3751794

Reputation:

How to calculate running time of an executable file?

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.

Upvotes: 4

Views: 3395

Answers (3)

barceloco
barceloco

Reputation: 458

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)?

Upvotes: 5

Luis Mendo
Luis Mendo

Reputation: 112779

You could always include

tic

at the beginning of the executable, and then

disp(toc)

at the end.

Upvotes: 2

A Hernandez
A Hernandez

Reputation: 484

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

Upvotes: 1

Related Questions