What is the formula to evaluate the execution time of a fortran program

If the fortran program compiles into an executable file, and you are running on Unix or Linux or other *nix variant, at a shellprompt type: time fortran-program-command (of course after time, type in whatever command you would normally have typed to run the program) - note that the "time" command isn't asking the system to run it, just to time it for you. And it applies to any program, not just fortran.

That's the simple solution, though I suspect there might be more to it than that, for example do you want the program to time its own execution time, and then process the result?

Your question doesn't actually make much sense to me, a formula is used to perform a calculation on one or more values, not to execute a command such as "time my program".


Thanks for your reply! I am not writing a program. I am taking an existing program and computing the execution time of the program. After I compute the execution time, I will use that information to compute the speedup time for that program. Speedup formula is Sp = T1 / Tp.

Sorry, I still don't understand. Do you want to know HOW to calculate the elapsed time of a program?


If you have a formula to compute execution or elaspe time for serial and parallel fortran program, please post them.

Well then, I would still use the "time" command (NB I've edited my last post because I put run when I meant time - it's getting late!) - you didn't say if you're on a Unix system or not - but here's an example using the standard *nix command line:

~$ /usr/bin/time -o anyfile -a -f "%e" sleep 10
~$ cat anyfile

This is simply timing the elapsed time (-f "%e") of the "sleep 10" command, and appending the result into the file "anyfile". Unsurprisingly, it took ten seconds!

You could of course send the output to another program, or pipe it into another shell command.

You could put the timing of the old program and new program into a shell script, then using the shell read in the two output files and do the calculation. If you need help with the shell script part, just ask and I'll see what I can do, tomorrow. (It's now nearly 3am by my clock!)

Sorry, I am not a Fortran programmer (at least not since 25 years ago), so if it somehow needs to be done within the Fortran program, then I'm afraid I can't help any more.


Thanks for your help. Computing the execution time is on a unix system but I don't get to enter anything in unix. I get a fortran program on paper and told to determine the serial and parallel execution time.

So count how many instructions it would take to execute.

Grab an algorithms book or tutorial and read a little bit, if you're thinking you're going to get a ready made formula like a 'typical' math formula, you're on the wrong track. You might want to read about asymptotic analysis, runtime analysis, Big O, and connected topics that come up in searches. (I'm just giving you some terms to search for so you aren't at a loss where to start). The beginning of CLRS (Introduction to Algorithms by Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Cliff Stein, published by MIT Press and McGraw-Hill) introduces everything you need to know to analyze *most* (and by most I mean simple) programs, so if you're still at a loss after looking into other sources, check that out.