00001 #include <flgrCoreData.h>
00002 #include <flgrCoreThreads.h>
00003 #include <flgrCoreThreadsAuto.h>
00004 #include <flgrCoreMalloc.h>
00005 #include <flgrImageIO.h>
00006 #include <flgrMorphoBase.h>
00007
00008 #include <time.h>
00009
00016 #define BENCH_FUCTION(nbtime,textinfo,function,...) \
00017 { \
00018 time_t before_t, after_t; \
00019 clock_t before_c, after_c; \
00020 int i; \
00021 \
00022 before_t = time(NULL); \
00023 before_c = clock(); \
00024 \
00025 for(i=0;i<nbtime;i++) { \
00026 function(__VA_ARGS__); \
00027 } \
00028 \
00029 after_t = time(NULL); \
00030 after_c = clock(); \
00031 \
00032 printf(textinfo " System time : %d us, CPU time : %d us \n", \
00033 (int) (((after_t-before_t)*1000000)/nbtime), \
00034 (int) ((after_c-before_c)/(CLOCKS_PER_SEC/1000000)/nbtime)); \
00035 }
00036
00037
00038
00039
00040
00041
00042 int main(int argc, char *argv[]) {
00043 FLGR_Data2D *imin;
00044 FLGR_Data2D *imDest1;
00045 FLGR_Data2D *imDest2;
00046 FLGR_Data2D *nhb;
00047 int nb_threads;
00048
00049 if(argc <= 1) {
00050 POST_ERROR("Command line : %s <nb_thread> \n",argv[0]);
00051 return 1;
00052 }
00053
00054 sscanf(argv[1],"%d",&nb_threads);
00055
00056 imin = flgr2d_load_pgm("../../images/gray/cameraman.pgm");
00057 imDest1 = flgr2d_create_pixmap_from(imin);
00058 imDest2 = flgr2d_create_pixmap_from(imin);
00059 nhb = flgr2d_create_neighborhood(3,3,1,FLGR_UINT8,FLGR_RECT,FLGR_8_CONNEX);
00060
00061
00062 BENCH_FUCTION(10000,"Median",
00063 flgr2d_median,imDest1, imin, nhb);
00064
00065
00066
00067 BENCH_FUCTION(10000,"Auto Multi-thread Median",
00068 flgr2d_thread_function_data2d_data2d_nhb,
00069 flgr2d_median,imDest2,imin,nhb,nb_threads);
00070
00071 flgr2d_save_pgm(imDest1,"median",5);
00072 flgr2d_save_pgm(imDest2,"median_multithreaded_auto",5);
00073
00074 flgr2d_destroy(imin);
00075 flgr2d_destroy(imDest1);
00076 flgr2d_destroy(imDest2);
00077 flgr2d_destroy(nhb);
00078
00079 return 0;
00080 }
00081
00082