]> Creatis software - gdcm.git/blob - Example/exPrintTime.cxx
COMP: Remove call to problematic fprintf
[gdcm.git] / Example / exPrintTime.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: exPrintTime.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/10/21 08:43:32 $
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  ///usr/include/bits/time.h:41: 
33 //                      warning: this is the location of the previous definition
34
35
36 //Generated file:
37 #include "gdcmDataImages.h"
38 int main(int, char *[])
39 {
40    clock_t r1, r2, r3, r4;
41    struct tms tms1, tms2, tms3, tms4;
42    gdcm::File *e1;
43
44    //std::ostream os = std::cout;
45    //std::ostringstream s;
46
47    int i = 0;
48    while( gdcmDataImages[i] != 0 )
49    {
50       std::string filename = GDCM_DATA_ROOT;
51       filename += "/";  //doh!
52       filename += gdcmDataImages[i];
53
54       e1= new gdcm::File( );
55       r1 = times(&tms1);
56       e1->SetFileName( filename );
57       e1->Load( );
58       r2 = times(&tms2);
59       if (!e1->IsReadable())
60       std::cout << "-----------Not Readable " << std::endl;
61       delete e1;
62       e1= new gdcm::File( );
63       e1->SetLoadMode( gdcm::LD_NOSEQ | gdcm::LD_NOSHADOW );
64       r3 = times(&tms3);
65       e1->SetFileName( filename );
66       e1->Load( );
67       
68       r4 = times(&tms4);
69       if (!e1->IsReadable())
70          std::cout << "-----------Not Readable " << std::endl;
71       delete e1;
72  
73       std::cout 
74         << std::setw(60-strlen(gdcmDataImages[i])) << " "
75         << gdcmDataImages[i] << "   " 
76         << (long) ((tms2.tms_utime)  - (tms1.tms_utime)) 
77         << " vs  "
78         << (long) ((tms4.tms_utime)  - (tms3.tms_utime));
79                 
80       std::cout << "\twith clock time : " << r2-r1 << " vs " << r4-r3 
81           << std::endl;
82
83       i++;
84    }
85
86    std::cout << "---------------------------------------------------" << std::endl;
87
88    r1 = times(&tms1);
89    for(int k=0;k<1; k++) // run many tiles to increase time ...
90    {
91       i=0;
92       while( gdcmDataImages[i] != 0 )
93       {
94          std::string filename = GDCM_DATA_ROOT;
95          filename += "/";  //doh!
96          filename += gdcmDataImages[i];
97
98          e1= new gdcm::File( );
99          e1->SetFileName( filename );
100          e1->Load( ); 
101          if (!e1->IsReadable())
102             std::cout << "-----------Not Readable " << std::endl;
103          delete e1;
104
105         i++;
106     }
107  
108  }
109    r2 = times(&tms2);
110
111 // ---------------------------
112    r3 = times(&tms3);
113    for(int k=0;k<1; k++)
114    {
115
116      i=0;
117      while( gdcmDataImages[i] != 0 )
118      {
119         std::string filename = GDCM_DATA_ROOT;
120         filename += "/";  //doh!
121         filename += gdcmDataImages[i];
122
123         e1= new gdcm::File( );
124         e1->SetLoadMode( gdcm::LD_NOSEQ | gdcm::LD_NOSHADOW );
125         e1->SetFileName( filename );
126         e1->Load( );
127         if (!e1->IsReadable())
128           std::cout << "-----------Not Readable " << std::endl;
129         delete e1;
130         i++;
131       }
132    }
133     r4 = times(&tms4);
134
135     std::cout  
136           << (long) ((tms2.tms_utime)  - (tms1.tms_utime)) 
137           << "\t\t "
138           << (long) ((tms4.tms_utime)  - (tms3.tms_utime)) 
139           << std::endl;
140           std::cout << "---------------------------------------------------" << std::endl;
141
142    return 0;
143 }