Simple programs can be implemented through commands
[Plain]
# Time./test
Real 0m2. 033 s
User 0m2. 032 s
Sys 0m0. 000 s
# Time./test
Real 0m2. 033 s
User 0m2. 032 s
Sys 0m0. 000 s
If the time command is not convenient, you can use system functions.
[Cpp]
# Include <sys/times. h>
// The user obtains the user time and system time.
Static struct tms tms_start;
Static struct tms tms_end;
// Used to get the clock-up time
Static clock_t c_start;
Static clock_t c_end;
Void debug_times_start ()
{
Memset (& tms_start, 0, sizeof (struct tms ));
Memset (& tms_end, 0, sizeof (struct tms ));
C_start = times (& tms_start );
}
Void debug_times_end ()
{
C_end = times (& tms_end );
Printf ("clock time: % ld, user/system cpu time: % ld/% ld \ r \ n ",
C_end-c_start,
Tms_end.tms_utime-tms_start.tms_utime,
Tms_end.tms_stime-tms_start.tms_stime );
}
# Include <sys/times. h>
// The user obtains the user time and system time.
Static struct tms tms_start;
Static struct tms tms_end;
// Used to get the clock-up time
Static clock_t c_start;
Static clock_t c_end;
Void debug_times_start ()
{
Memset (& tms_start, 0, sizeof (struct tms ));
Memset (& tms_end, 0, sizeof (struct tms ));
C_start = times (& tms_start );
}
Void debug_times_end ()
{
C_end = times (& tms_end );
Printf ("clock time: % ld, user/system cpu time: % ld/% ld \ r \ n ",
C_end-c_start,
Tms_end.tms_utime-tms_start.tms_utime,
Tms_end.tms_stime-tms_start.tms_stime );
}