I have one or more functions separate from main() , that besides the return value , must also return the time it tooked to process.
How can I do that ?
Eko
1
Junior Poster in Training
Recommended Answers
Jump to Postmake a parameter that is a pointer to the object you want the function to return Example:
int foo( size_t* time) { *time = 123; return 1; } int main() { size_t processing_time; int x = foo( &processing_time ); }
If you want to profile the entire …
Jump to Postsee my second example -- you have to get the time before processing starts and again after, then subtract the two. And the time is in whole numbers. If you want fractions than divide by 100 when printing it.
print ("time = %f\n", (float)processing_time/100.0F);
Jump to Postdid you include time.h? Also, if you are compiling as c++ then change variable end to something else because end is a c++ key word.
All 9 Replies
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
Eko
1
Junior Poster in Training
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
Eko
1
Junior Poster in Training
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
Eko
1
Junior Poster in Training
Ravalon
62
Posting Whiz in Training
Eko
1
Junior Poster in Training
motogeeeksatyam
-8
Newbie Poster
Salem
commented:
Just another stupid poster, 3 years late with the "void main" program and no code tags - nothing to see here, move along.
-4
Narue
commented:
I can't imagine the confusion of ideas that gives rise to code like that.
-4
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.