add timing to compress and decompress

This commit is contained in:
Aaron Boxer 2015-06-15 20:16:32 -04:00 committed by Antonin Descampe
parent c6c49865fe
commit 56d3f5af6e
2 changed files with 71 additions and 0 deletions

View File

@ -57,6 +57,9 @@
#define strncasecmp _strnicmp #define strncasecmp _strnicmp
#else #else
#include <strings.h> #include <strings.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/times.h>
#endif /* _WIN32 */ #endif /* _WIN32 */
#include "opj_apps_config.h" #include "opj_apps_config.h"
@ -1535,6 +1538,31 @@ static void info_callback(const char *msg, void *client_data) {
fprintf(stdout, "[INFO] %s", msg); fprintf(stdout, "[INFO] %s", msg);
} }
OPJ_FLOAT64 opj_clock(void) {
#ifdef _WIN32
/* _WIN32: use QueryPerformance (very accurate) */
LARGE_INTEGER freq , t ;
/* freq is the clock speed of the CPU */
QueryPerformanceFrequency(&freq) ;
/* cout << "freq = " << ((double) freq.QuadPart) << endl; */
/* t is the high resolution performance counter (see MSDN) */
QueryPerformanceCounter ( & t ) ;
return ( t.QuadPart /(OPJ_FLOAT64) freq.QuadPart ) ;
#else
/* Unix or Linux: use resource usage */
struct rusage t;
OPJ_FLOAT64 procTime;
/* (1) Get the rusage data structure at this moment (man getrusage) */
getrusage(0,&t);
/* (2) What is the elapsed time ? - CPU time = User time + System time */
/* (2a) Get the seconds */
procTime = (OPJ_FLOAT64)(t.ru_utime.tv_sec + t.ru_stime.tv_sec);
/* (2b) More precisely! Get the microseconds part ! */
return ( procTime + (OPJ_FLOAT64)(t.ru_utime.tv_usec + t.ru_stime.tv_usec) * 1e-6 ) ;
#endif
}
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/** /**
* OPJ_COMPRESS MAIN * OPJ_COMPRESS MAIN
@ -1548,6 +1576,7 @@ int main(int argc, char **argv) {
opj_codec_t* l_codec = 00; opj_codec_t* l_codec = 00;
opj_image_t *image = NULL; opj_image_t *image = NULL;
raw_cparameters_t raw_cp; raw_cparameters_t raw_cp;
OPJ_SIZE_T num_compressed_files = 0;
char indexfilename[OPJ_PATH_LEN]; /* index file name */ char indexfilename[OPJ_PATH_LEN]; /* index file name */
@ -1558,6 +1587,7 @@ int main(int argc, char **argv) {
OPJ_BOOL bSuccess; OPJ_BOOL bSuccess;
OPJ_BOOL bUseTiles = OPJ_FALSE; /* OPJ_TRUE */ OPJ_BOOL bUseTiles = OPJ_FALSE; /* OPJ_TRUE */
OPJ_UINT32 l_nb_tiles = 4; OPJ_UINT32 l_nb_tiles = 4;
OPJ_FLOAT64 t = opj_clock();
/* set encoding parameters to default values */ /* set encoding parameters to default values */
opj_set_default_encoder_parameters(&parameters); opj_set_default_encoder_parameters(&parameters);
@ -1822,6 +1852,7 @@ int main(int argc, char **argv) {
return 1; return 1;
} }
num_compressed_files++;
fprintf(stdout,"[INFO] Generated outfile %s\n",parameters.outfile); fprintf(stdout,"[INFO] Generated outfile %s\n",parameters.outfile);
/* close and free the byte stream */ /* close and free the byte stream */
opj_stream_destroy(l_stream); opj_stream_destroy(l_stream);
@ -1839,5 +1870,9 @@ int main(int argc, char **argv) {
if(parameters.cp_matrice) free(parameters.cp_matrice); if(parameters.cp_matrice) free(parameters.cp_matrice);
if(raw_cp.rawComps) free(raw_cp.rawComps); if(raw_cp.rawComps) free(raw_cp.rawComps);
t = opj_clock() - t;
fprintf(stdout, "encode time: %d ms \n", (int)((t * 1000)/num_compressed_files));
scanf("%d");
return 0; return 0;
} }

View File

@ -56,6 +56,9 @@
#define strncasecmp _strnicmp #define strncasecmp _strnicmp
#else #else
#include <strings.h> #include <strings.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/times.h>
#endif /* _WIN32 */ #endif /* _WIN32 */
#include "openjpeg.h" #include "openjpeg.h"
@ -840,6 +843,30 @@ int parse_DA_values( char* inArg, unsigned int *DA_x0, unsigned int *DA_y0, unsi
} }
} }
OPJ_FLOAT64 opj_clock(void) {
#ifdef _WIN32
/* _WIN32: use QueryPerformance (very accurate) */
LARGE_INTEGER freq , t ;
/* freq is the clock speed of the CPU */
QueryPerformanceFrequency(&freq) ;
/* cout << "freq = " << ((double) freq.QuadPart) << endl; */
/* t is the high resolution performance counter (see MSDN) */
QueryPerformanceCounter ( & t ) ;
return ( t.QuadPart /(OPJ_FLOAT64) freq.QuadPart ) ;
#else
/* Unix or Linux: use resource usage */
struct rusage t;
OPJ_FLOAT64 procTime;
/* (1) Get the rusage data structure at this moment (man getrusage) */
getrusage(0,&t);
/* (2) What is the elapsed time ? - CPU time = User time + System time */
/* (2a) Get the seconds */
procTime = (OPJ_FLOAT64)(t.ru_utime.tv_sec + t.ru_stime.tv_sec);
/* (2b) More precisely! Get the microseconds part ! */
return ( procTime + (OPJ_FLOAT64)(t.ru_utime.tv_usec + t.ru_stime.tv_usec) * 1e-6 ) ;
#endif
}
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/** /**
@ -1135,6 +1162,8 @@ int main(int argc, char **argv)
img_fol_t img_fol; img_fol_t img_fol;
dircnt_t *dirptr = NULL; dircnt_t *dirptr = NULL;
int failed = 0; int failed = 0;
OPJ_FLOAT64 t, tCumulative = 0;
OPJ_UINT32 numDecompressedImages = 0;
/* set decoding parameters to default values */ /* set decoding parameters to default values */
set_default_parameters(&parameters); set_default_parameters(&parameters);
@ -1239,6 +1268,8 @@ int main(int argc, char **argv)
opj_set_warning_handler(l_codec, warning_callback,00); opj_set_warning_handler(l_codec, warning_callback,00);
opj_set_error_handler(l_codec, error_callback,00); opj_set_error_handler(l_codec, error_callback,00);
t = opj_clock();
/* Setup the decoder decoding parameters using user parameters */ /* Setup the decoder decoding parameters using user parameters */
if ( !opj_setup_decoder(l_codec, &(parameters.core)) ){ if ( !opj_setup_decoder(l_codec, &(parameters.core)) ){
fprintf(stderr, "ERROR -> opj_decompress: failed to setup the decoder\n"); fprintf(stderr, "ERROR -> opj_decompress: failed to setup the decoder\n");
@ -1303,6 +1334,9 @@ int main(int argc, char **argv)
fprintf(stdout, "tile %d is decoded!\n\n", parameters.tile_index); fprintf(stdout, "tile %d is decoded!\n\n", parameters.tile_index);
} }
tCumulative += opj_clock() - t;
numDecompressedImages++;
/* Close the byte stream */ /* Close the byte stream */
opj_stream_destroy(l_stream); opj_stream_destroy(l_stream);
@ -1501,6 +1535,8 @@ int main(int argc, char **argv)
if(failed) remove(parameters.outfile); if(failed) remove(parameters.outfile);
} }
destroy_parameters(&parameters); destroy_parameters(&parameters);
fprintf(stdout, "decode time: %d ms \n", (int)( (tCumulative * 1000) / numDecompressedImages));
scanf("%d");
return failed ? EXIT_FAILURE : EXIT_SUCCESS; return failed ? EXIT_FAILURE : EXIT_SUCCESS;
} }
/*end main*/ /*end main*/