0

In a program which I built for a university project, I have to evaluate its execution time in relation to the number of time it executes (the program is basically a for cycle). The number of cycles is passed as a command-line argument in the terminal.

As the title says, is there an easier way to produce an execution time log that looks like this (using the c++ fstream library maybe):

N of steps        Time (s)
1                 0
10                0.2
100               1

etc...            etc...

Obviously, the dumb way to do it is:

  • Run the code changing manually the number of cycles.
  • Tabulating the N of steps and the user time as the process goes on (the shell (I use bash if I'm not mistaken) is time <executable name> <N of cycles> )

but for that, I have to repeat the process something like a thousand times, so i thought that an "automatic" logging should do the trick.

The question is: How can I implement that "automatic logging" in order to save precious time?

Jack
  • 23
  • 4
  • 1
    You can just write a script (using Bash/Batch/Python/Perl/...) that calls your program with the proper command line argument and then logs the time somewhere else. – UnholySheep Dec 30 '16 at 15:58
  • first of all thanks for the answer! awesome, that would be my first script :) but i'm very new to this thing... is this guide good for what i'm trying to do? https://help.ubuntu.com/community/Beginners/BashScripting – Jack Dec 30 '16 at 16:12
  • I don't use Bash myself (because 1. I'm working primarily on Windows and 2. I don't like its syntax) and tend to prefer Python or Ruby for this kind of task. That being said it does look like it covers most topics, but you could probably just google the necessary parts and put something together quickly. – UnholySheep Dec 30 '16 at 16:26
  • http://stackoverflow.com/questions/3737740/is-there-a-better-way-to-run-a-command-n-times-in-bash use g++ in script – Shankar Shastri Dec 30 '16 at 17:19

0 Answers0