| | |
Can a function return 2 values?
![]() |
make a parameter that is a pointer to the object you want the function to return Example:
If you want to profile the entire function then the function doesn't need to know anything about it.
C Syntax (Toggle Plain Text)
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 function then the function doesn't need to know anything about it.
C Syntax (Toggle Plain Text)
int main() { time_t start, end; start = time(0); foo(); end = time(0); // now just subtract the two times to get processing time return 0l; }
Last edited by Ancient Dragon; Jan 21st, 2007 at 8:49 am.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
After you said , at the first method ,i came up with this:
I don't know if it's the greatest solution , but it works(i quess),only that isn't very accuarate .How can i make it display small time values(like 0.001 seconds)
The second method doesn't work
C Syntax (Toggle Plain Text)
#include <stdio.h> #include <time.h> int foo( clock_t* time) { int x=0; while(x<1000000000) x++; *time=clock()/ (long) CLK_TCK; return x; } int main() { clock_t processing_time; int x = foo( &processing_time ); printf("%d\n x value is %d= ",processing_time,x); return 0; }
The second method doesn't work
Last edited by Eko; Jan 21st, 2007 at 9:10 am.
"Get rich or die tryin"(50-cent)
see 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.
C Syntax (Toggle Plain Text)
print ("time = %f\n", (float)processing_time/100.0F);
Last edited by Ancient Dragon; Jan 21st, 2007 at 11:35 am.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
did 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.
Last edited by Ancient Dragon; Jan 21st, 2007 at 11:37 am.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
C Syntax (Toggle Plain Text)
#include <stdio.h> #include <time.h> #include <dos.h> int foo() { int x=0; while(x<1000000) x++; return x; } int main() { time_t start, end; int x,time; start = time(0); x=foo(); end = time(0); // now just subtract the two times to get processing time time=end-start; printf("%d s: ",time); return 0; }
"Get rich or die tryin"(50-cent)
•
•
•
•
C Syntax (Toggle Plain Text)
#include <stdio.h> #include <time.h> #include <dos.h> int foo() { int x=0; while(x<1000000) x++; return x; } int main() { time_t start, end; int x,time; start = time(0); x=foo(); end = time(0); // now just subtract the two times to get processing time time=end-start; printf("%d s: ",time); return 0; }
It's hard to be humble when you're as gifted as I am at pretending to be an expert.
![]() |
Similar Threads
- Compiler error (C++)
- Help with FindExecutable() (C)
- OK im restarting (C++)
- need help with code (C++)
Other Threads in the C Forum
- Previous Thread: Multifile programs
- Next Thread: Doubly linked circular list
| Thread Tools | Search this Thread |
#include * adobe ansi api array asterisks binarysearch centimeter changingto char character cm copyimagefile cprogramme creafecopyofanytypeoffileinc csyntax database directory dynamic execv feet fgets file fork function getlasterror getlogicaldrivestrin givemetehcodez global grade gtkgcurlcompiling gtkwinlinux hacking hardware highest histogram ide include incrementoperators infiniteloop input interest kernel keyboard kilometer license linked linkedlist linux linuxsegmentationfault list locate logical_drives looping loopinsideloop. lowest match matrix meter microsoft motherboard mqqueue number odf opendocumentformat opensource owf pattern pdf performance pointer posix probleminc process program programming radix recursion recv repetition research reversing segmentationfault sequential single socket socketprograming standard string systemcall threads turboc unix user voidmain() wab whythiscodecausesegmentationfault windows.h windowsapi






