]> Creatis software - gdcm.git/blob - Example/TestPrintTime.cxx
35ddc5a1506f581f5670d80dba5d315e999a1db0
[gdcm.git] / Example / TestPrintTime.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: TestPrintTime.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/05/10 12:12:02 $
7   Version:   $Revision: 1.1 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See Doc/License.txt or
11   http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
12                                                                                 
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16                                                                                 
17 =========================================================================*/
18
19 // TODO : check what's *actually* usefull
20
21 #include "gdcmFile.h"
22 #include "gdcmUtil.h"
23 #include "gdcmCommon.h"
24
25 #include <iostream>
26 #include <time.h>
27 #include <sys/times.h>
28
29 #include <iomanip> // for std::ios::left, ...
30
31 // Where is it?
32 #define CLK_TCK 1
33
34
35 //Generated file:
36 #include "gdcmDataImages.h"
37 int main(int, char *[])
38 {
39    clock_t r1, r2, r3, r4;
40    struct tms tms1, tms2, tms3, tms4;
41    gdcm::File *e1;
42
43    //std::ostream os = std::cout;
44    //std::ostringstream s;
45
46    int i = 0;
47    while( gdcmDataImages[i] != 0 )
48    {
49       std::string filename = GDCM_DATA_ROOT;
50       filename += "/";  //doh!
51       filename += gdcmDataImages[i];
52
53       e1= new gdcm::File( );
54       r1 = times(&tms1);
55       e1->Load( filename );
56       r2 = times(&tms2);
57       if (!e1->IsReadable())
58       std::cout << "-----------Not Readable " << std::endl;
59       delete e1;
60       e1= new gdcm::File( );
61       e1->SetLoadMode( NO_SEQ | NO_SHADOW );
62       r3 = times(&tms3);
63       e1->Load( filename );
64       r4 = times(&tms4);
65       if (!e1->IsReadable())
66          std::cout << "-----------Not Readable " << std::endl;
67       delete e1;
68  
69       std::cout 
70         << std::setw(60-strlen(gdcmDataImages[i])) << " "
71         << gdcmDataImages[i] << "   " 
72         << (long) ((tms2.tms_utime)  - (tms1.tms_utime)) 
73         << " vs  "
74         << (long) ((tms4.tms_utime)  - (tms3.tms_utime));
75                 
76       std::cout << "\twith clock time : " << r2-r1 << " vs " << r4-r3 
77           << std::endl;
78
79       i++;
80    }
81
82    std::cout << "---------------------------------------------------" << std::endl;
83
84    r1 = times(&tms1);
85    for(int k=0;k<1; k++) // run many tiles to increase time ...
86    {
87       i=0;
88       while( gdcmDataImages[i] != 0 )
89       {
90          std::string filename = GDCM_DATA_ROOT;
91          filename += "/";  //doh!
92          filename += gdcmDataImages[i];
93
94          e1= new gdcm::File( );
95          e1->Load( filename );
96          if (!e1->IsReadable())
97             std::cout << "-----------Not Readable " << std::endl;
98          delete e1;
99
100         i++;
101     }
102  
103  }
104    r2 = times(&tms2);
105
106 // ---------------------------
107    r3 = times(&tms3);
108    for(int k=0;k<1; k++)
109    {
110
111      i=0;
112      while( gdcmDataImages[i] != 0 )
113      {
114         std::string filename = GDCM_DATA_ROOT;
115         filename += "/";  //doh!
116         filename += gdcmDataImages[i];
117
118         e1= new gdcm::File( );
119         e1->SetLoadMode( NO_SEQ | NO_SHADOW );
120         e1->Load( filename );
121         if (!e1->IsReadable())
122           std::cout << "-----------Not Readable " << std::endl;
123         delete e1;
124         i++;
125       }
126    }
127     r4 = times(&tms4);
128
129     std::cout  
130           << (long) ((tms2.tms_utime)  - (tms1.tms_utime)) 
131           << "\t\t "
132           << (long) ((tms4.tms_utime)  - (tms3.tms_utime)) 
133           << std::endl;
134           std::cout << "---------------------------------------------------" << std::endl;
135
136    return 0;
137 }