00001
00002 #ifdef HAVE_CONFIG_H
00003 # include <config.h>
00004 #endif
00005
00006 #include <iostream>
00007 #include <strstream>
00008 #include <cassert>
00009 #include "utils.h"
00010
00011 using std::cout;
00012 using std::endl;
00013 using std::istrstream;
00014
00015 const char *ss_data = "A BC DE FGHI JKLM NO\0";
00016
00017 #if 0 // just used temporarially for some optimisation tests.
00018 inline uint8 Read1diff
00019 (
00020 std::istream& in
00021 )
00022 {
00023 return static_cast<uint8>(in.get());
00024 }
00025
00026 inline uint32 Read4diff
00027 (
00028 std::istream& in
00029 )
00030 {
00031 return static_cast<uint32>(in.get() | (in.get()<<8) | (in.get()<<16) | (in.get()<<24));
00032 }
00033
00034 #include <sys/time.h>
00035 #include <fstream>
00036
00037 void speedtest()
00038 {
00039 timeval tvstart;
00040 timeval tvend;
00041 timeval tvstart_diff;
00042 timeval tvend_diff;
00043
00044 std::ifstream file("random");
00045 assert(!file.fail());
00046
00047 gettimeofday(&tvstart, NULL);
00048
00049 while(!file.eof())
00050 uint8 ui8 = Read4(file);
00051
00052 gettimeofday(&tvend, NULL);
00053
00054
00055
00056 std::ifstream file_diff("random");
00057 assert(!file_diff.fail());
00058
00059 gettimeofday(&tvstart_diff, NULL);
00060
00061 while(!file_diff.eof())
00062 uint8 ui8 = Read4diff(file_diff);
00063
00064 gettimeofday(&tvend_diff, NULL);
00065
00066 cout << tvstart.tv_sec << '\t' << tvstart.tv_usec << endl;
00067 cout << tvend.tv_sec << '\t' << tvend.tv_usec << endl;
00068 cout << "---------------------" << endl;
00069 cout << tvend.tv_sec - tvstart.tv_sec << '\t' << tvend.tv_usec - tvstart.tv_usec << endl;
00070 cout << endl;
00071 cout << tvstart_diff.tv_sec << '\t' << tvstart_diff.tv_usec << endl;
00072 cout << tvend_diff.tv_sec << '\t' << tvend_diff.tv_usec << endl;
00073 cout << "---------------------" << endl;
00074 cout << tvend_diff.tv_sec - tvstart_diff.tv_sec << '\t' << tvend_diff.tv_usec - tvstart_diff.tv_usec << endl;
00075 cout << endl;
00076 }
00077 #endif
00078
00079 int main(int argc, char *argv[])
00080 {
00081 istrstream iss(ss_data);
00082
00083 uint8 outread1 = Read1(iss);
00084 cout << static_cast<char>(outread1) << endl;
00085 assert(static_cast<char>(outread1)=='A');
00086
00087 assert(static_cast<char>(Read1(iss))==' ');
00088
00089 uint16 outread2 = Read2(iss);
00090 cout << static_cast<char>(outread2 & 0xff) << static_cast<char>((outread2>>8) & 0xff) << endl;
00091 assert(static_cast<char>(outread2 & 0xff)=='B');
00092 assert(static_cast<char>((outread2>>8) & 0xff)=='C');
00093
00094 assert(static_cast<char>(Read1(iss))==' ');
00095
00096 uint16 outread2high = Read2high(iss);
00097 cout << static_cast<char>((outread2high>>8) & 0xff) << static_cast<char>(outread2high & 0xff) << endl;
00098 assert(static_cast<char>(outread2high & 0xff)=='E');
00099 assert(static_cast<char>((outread2high>>8) & 0xff)=='D');
00100
00101 assert(static_cast<char>(Read1(iss))==' ');
00102
00103 uint32 outread4 = Read4(iss);
00104 cout << static_cast<char>(outread4 & 0xff) << static_cast<char>((outread4>>8) & 0xff)
00105 << static_cast<char>((outread4>>16) & 0xff) << static_cast<char>((outread4>>24) & 0xff) << endl;
00106 assert(static_cast<char>(outread4 & 0xff)=='F');
00107 assert(static_cast<char>((outread4>>8) & 0xff)=='G');
00108 assert(static_cast<char>((outread4>>16) & 0xff)=='H');
00109 assert(static_cast<char>((outread4>>24) & 0xff)=='I');
00110
00111 assert(static_cast<char>(Read1(iss))==' ');
00112
00113 uint32 outread4high = Read4high(iss);
00114 cout << static_cast<char>((outread4high>>24) & 0xff) << static_cast<char>((outread4high>>16) & 0xff)
00115 << static_cast<char>((outread4high>>8) & 0xff) << static_cast<char>(outread4high & 0xff) << endl;
00116 assert(static_cast<char>(outread4high & 0xff)=='M');
00117 assert(static_cast<char>((outread4high>>8) & 0xff)=='L');
00118 assert(static_cast<char>((outread4high>>16) & 0xff)=='K');
00119 assert(static_cast<char>((outread4high>>24) & 0xff)=='J');
00120
00121
00122
00123 return 0;
00124 }
00125
00126
00127
00128
00129
00130
00131