-
Notifications
You must be signed in to change notification settings - Fork 1
/
LZOTester.cc
160 lines (122 loc) · 3.71 KB
/
LZOTester.cc
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// LZOTester.cc
// Scott F. Kaplan -- sfkaplan@cs.utexas.edu
// August 1997
// A tester designed to work on the Lempel-Ziv-Oberhumer
// compression/decompression algorithm. Note that we've chosen to use
// the LZO1f variant--according to the results provided by Oberhumer,
// that variant does best with short compression sources.
using namespace std;
#include <iostream>
#include <stdlib.h>
#include "LZOTester.hh"
#include "lzo1f.h"
#include <time.h>
// Perform the actual task of timing the compression algorithm.
void
LZOTester::performCompressionTest
(void* uncompressedData,
unsigned int uncompressedBytes,
unsigned int& returnCompressedSize,
unsigned long long& returnCompressionTime) {
lzo_byte compressionBuffer[2 * uncompressedBytes];
lzo_byte _workingMemory[LZO1F_MEM_COMPRESS + 16];
lzo_uint compressedSize = sizeof(compressionBuffer);
int resultCode;
// Initialize the working memory.
lzo_byte* workingMemory = (lzo_byte*)LZO_ALIGN(_workingMemory, 16);
// Surround a call to the compression routine with a timing
// mechanism.
//START_MYTIMER;
//start
struct timespec start, stop;
long accum;
clock_gettime(CLOCK_REALTIME, &start);
//endstart
resultCode =
lzo1f_1_compress((lzo_byte*)uncompressedData,
uncompressedBytes,
compressionBuffer,
&compressedSize,
workingMemory);
//stop
clock_gettime(CLOCK_REALTIME, &stop);
accum = (stop.tv_sec - start.tv_sec)
+ (stop.tv_nsec - start.tv_nsec);
/// 1000000000.0;
returnCompressionTime = accum;
//endstop
//STOP_MYTIMER;
// Ensure that the compression was successful.
if (resultCode != LZO_E_OK) {
cerr << "LZO::performCompressionTest: "
<< "Compression failed = "
<< resultCode
<< endl;
exit(-1);
}
// Set the return values.
returnCompressedSize = compressedSize;
}
// Perform the actual task of timing the decompression algorithm.
void
LZOTester::performDecompressionTest
(void* uncompressedData,
unsigned int uncompressedBytes,
unsigned int& returnPreDecompressionSize,
unsigned long long& returnDecompressionTime) {
lzo_byte compressionBuffer[2 * uncompressedBytes];
lzo_byte decompressionBuffer[uncompressedBytes];
lzo_byte _workingMemory[LZO1F_MEM_COMPRESS + 16];
lzo_uint compressedSize;
lzo_uint decompressedSize;
int resultCode;
// Initialize the working memory.
lzo_byte* workingMemory = (lzo_byte*)LZO_ALIGN(_workingMemory, 16);
// Get a compressed copy of the page so that the decompression can
// be timed.
resultCode =
lzo1f_1_compress((lzo_byte*)uncompressedData,
uncompressedBytes,
compressionBuffer,
&compressedSize,
workingMemory);
// Ensure that the compression was successful.
if (resultCode != LZO_E_OK) {
cerr << "LZO::performDecompressionTest: "
<< "Compression failed = "
<< resultCode
<< endl;
exit(-1);
}
// Surround a call to the decompression routine with a timing
// mechanism.
//START_TIMER;
//start
struct timespec start, stop;
long accum;
clock_gettime(CLOCK_REALTIME, &start);
//endstart
resultCode = lzo1f_decompress(compressionBuffer,
compressedSize,
decompressionBuffer,
&decompressedSize,
0);
//stop
clock_gettime(CLOCK_REALTIME, &stop);
accum = (stop.tv_sec - start.tv_sec)
+ (stop.tv_nsec - start.tv_nsec);
/// 1000000000.0;
returnDecompressionTime = accum;
//endstop
// STOP_TIMER(returnDecompressionTime);
// Ensure that the decompression was successful.
if (resultCode != LZO_E_OK) {
cerr << "LZO::performDecompressionTest: "
<< "Decompression failed = "
<< resultCode
<< endl;
exit(-1);
}
// Set the return values.
returnPreDecompressionSize = compressedSize;
}