I am attempting to see have much run time a program takes, and eventually check the runtime of different pieces of the program. (As it runs it seems to get slower and slower without explanation)
Anyways, I tried the sample code posted on a super simple program.
If I wanted to use it at multiple stages in a larger program (in c) would I simply repeat the printf part? Or is there a better way to do this?
I am very new to programming, and got drafted into trying to fix up an inefficient and giant program for my university.
Any help is greatly appreciated

> As it runs it seems to get slower and slower without explanation
That sounds like it's consuming memory to me.

You haven't said which Operating system or compiler you're using.
Some come with $0 profilers.

> I am very new to programming, and got drafted into trying to fix up an inefficient and giant program for my university.
Who's managing this?
Throwing as many bodies at the problem as they can find isn't going to solve anything.

The program was originally written in Matlab, which I am very familiar with. It quickly became obvious that the program (multiple embedded For loops, thousands of runs and numerous random number generators) would be better for distribution and speed in C.
The OS I am using is the newest version of linux. I am using the gcc compiler that came with the OS.
What it comes down to, is I have about a year to finish the program, under a grant to teach non computer literate majors (me) how to program.
thanks for the help

Comments
i'ma give you some positive rep because ... well, just because. good luck. :)

> under a grant to teach non computer literate majors (me) how to program.
Wading through someone else's rotting dung pile of a program won't teach you how to program. At best, it will tell you how to recognise a bad program. What it will not do for sure is teach you how to create a good program.

Not knowing how to program is probably why the program is in the state that it's in already.

Basically, you're at the bottom of a hole, and someone's just given you a spade to start digging.

But anyway, if you're still up for the task, read this
http://unixhelp.ed.ac.uk/CGI/man-cgi?gprof
Essentially

gcc -pg prog.c
./a.out
gprof

Be sure you get plenty of practice on small programs to begin with. Interpreting profile data is both art and science.

I have about a year to finish the program, under a grant to teach non computer literate majors (me) how to program.

well, you're gonna learn alot. it won't be efficient learning, and you'll probably learn a lot of poor practices, just to "get the job done".

and you're probably be likely to learn to hate programming by the time it's all done with.

it's unfortunate your first real project is fixing someone else's mess.

but, also unfortunately, that's how many people get introduced at their first "real job" so... you're not alone.

good luck. come back and ask questions whenever you get stuck.

when asking questions, remember to post relevant code and use code tags, and describe what youve done, what you expected, and what you got.

This article has been dead for over six months. Start a new discussion instead.