File: rwregress.cc

package info (click to toggle)
exult 0.98rc1-2
  • links: PTS
  • area: contrib
  • in suites: woody
  • size: 6,924 kB
  • ctags: 8,928
  • sloc: cpp: 83,768; sh: 7,643; ansic: 4,328; makefile: 890; yacc: 618; lex: 255; xml: 19
file content (130 lines) | stat: -rw-r--r-- 3,458 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <iostream>
#include "utils.h"
#include <strstream>

using std::cout;
using std::endl;
using std::istrstream;

const char *ss_data = "A BC DE FGHI JKLM NO\0";

#if 0 // just used temporarially for some optimisation tests.
inline uint8 Read1diff
	(
	std::istream& in
	)
	{
	return static_cast<uint8>(in.get());
	}

inline uint32 Read4diff
	(
	std::istream& in
	)
	{
	return static_cast<uint32>(in.get() | (in.get()<<8) | (in.get()<<16) | (in.get()<<24));
	}

#include <sys/time.h>
#include <fstream>

void speedtest()
{
	timeval tvstart;
	timeval tvend;
	timeval tvstart_diff;
	timeval tvend_diff;
	
	std::ifstream file("random");
	assert(!file.fail());
	
	gettimeofday(&tvstart, NULL);
	
	while(!file.eof())
		uint8 ui8 = Read4(file);
	
	gettimeofday(&tvend, NULL);
	
	//-------------------------
	
	std::ifstream file_diff("random");
	assert(!file_diff.fail());
	
	gettimeofday(&tvstart_diff, NULL);
	
	while(!file_diff.eof())
		uint8 ui8 = Read4diff(file_diff);
	
	gettimeofday(&tvend_diff, NULL);
	
	cout << tvstart.tv_sec << '\t' << tvstart.tv_usec << endl;
	cout << tvend.tv_sec << '\t' << tvend.tv_usec << endl;
	cout << "---------------------" << endl;
	cout << tvend.tv_sec - tvstart.tv_sec << '\t' << tvend.tv_usec - tvstart.tv_usec << endl;
	cout << endl;
	cout << tvstart_diff.tv_sec << '\t' << tvstart_diff.tv_usec << endl;
	cout << tvend_diff.tv_sec << '\t' << tvend_diff.tv_usec << endl;
	cout << "---------------------" << endl;
	cout << tvend_diff.tv_sec - tvstart_diff.tv_sec << '\t' << tvend_diff.tv_usec - tvstart_diff.tv_usec << endl;
	cout << endl;
}
#endif

int main(int argc, char *argv[])
{
	istrstream iss(ss_data);
	
	uint8 outread1 = Read1(iss);
	cout << static_cast<char>(outread1) << endl;
	assert(static_cast<char>(outread1)=='A');
	
	assert(static_cast<char>(Read1(iss))==' ');
	
	uint16 outread2 = Read2(iss);
	cout << static_cast<char>(outread2 & 0xff) << static_cast<char>((outread2>>8) & 0xff) << endl;
	assert(static_cast<char>(outread2 & 0xff)=='B');
	assert(static_cast<char>((outread2>>8) & 0xff)=='C');
	
	assert(static_cast<char>(Read1(iss))==' ');
	
	uint16 outread2high = Read2high(iss);
	cout << static_cast<char>((outread2high>>8) & 0xff) << static_cast<char>(outread2high & 0xff) << endl;
	assert(static_cast<char>(outread2high & 0xff)=='E');
	assert(static_cast<char>((outread2high>>8) & 0xff)=='D');
	
	assert(static_cast<char>(Read1(iss))==' ');
	
	uint32 outread4 = Read4(iss);
	cout << static_cast<char>(outread4 & 0xff) << static_cast<char>((outread4>>8) & 0xff)
		 << static_cast<char>((outread4>>16) & 0xff)  << static_cast<char>((outread4>>24) & 0xff) << endl;
	assert(static_cast<char>(outread4 & 0xff)=='F');
	assert(static_cast<char>((outread4>>8) & 0xff)=='G');
	assert(static_cast<char>((outread4>>16) & 0xff)=='H');
	assert(static_cast<char>((outread4>>24) & 0xff)=='I');
	
	assert(static_cast<char>(Read1(iss))==' ');
	
	uint32 outread4high = Read4high(iss);
	cout << static_cast<char>((outread4high>>24) & 0xff) << static_cast<char>((outread4high>>16) & 0xff)
		 << static_cast<char>((outread4high>>8) & 0xff)  << static_cast<char>(outread4high & 0xff) << endl;
	assert(static_cast<char>(outread4high & 0xff)=='M');
	assert(static_cast<char>((outread4high>>8) & 0xff)=='L');
	assert(static_cast<char>((outread4high>>16) & 0xff)=='K');
	assert(static_cast<char>((outread4high>>24) & 0xff)=='J');
	
	//speedtest();
	
	return 0;
}