-
Notifications
You must be signed in to change notification settings - Fork 1
/
WKdmTester.cc
114 lines (82 loc) · 2.8 KB
/
WKdmTester.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
// WKdmTester.cc
// Scott F. Kaplan -- [email protected]
// October 1997
// A tester designed to work on the Wilson-Kaplan-0
// compression/decompression algorithm. Note that it note only
// performs the requested compression and decompression, but also
// performs and keeps extra statisics for its own experiements that
// measure characteristics specific to this algorithm.
#include <iostream>
#include "WKdmTester.hh"
#include "WKdm.h"
const unsigned int bytesPerWK_word = sizeof(WK_word) / sizeof(char);
// Perform the actual task of timing the compression algorithm.
void
WKdmTester::performCompressionTest
(void* uncompressedData,
unsigned int uncompressedBytes,
unsigned int& returnCompressedSize,
unsigned long long& returnCompressionTime) {
WK_word compressionBuffer[4 * uncompressedBytes / bytesPerWK_word];
// Surround a call to the compression routine with a timing
// mechanism.
//START_TIMER;
//this is an attempt to replace the timer
//start
struct timespec start, stop;
long accum;
clock_gettime(CLOCK_REALTIME, &start);
//endstart
returnCompressedSize =
WKdm_compress((WK_word*)uncompressedData,
compressionBuffer,
uncompressedBytes / bytesPerWK_word);
//stop
clock_gettime(CLOCK_REALTIME, &stop);
accum = (stop.tv_sec - start.tv_sec)
+ (stop.tv_nsec - start.tv_nsec);
/// 1000000000L;
returnCompressionTime = accum;
//endstop
// Set the value that will return the compression time.
//STOP_TIMER(returnCompressionTime);
}
// Perform the actual task of timing the decompression algorithm.
void
WKdmTester::performDecompressionTest
(void* uncompressedData,
unsigned int uncompressedBytes,
unsigned int& returnPreDecompressionSize,
unsigned long long& returnDecompressionTime) {
returnPreDecompressionSize = 0;
returnDecompressionTime = 0;
unsigned int uncompressedWords = uncompressedBytes / bytesPerWK_word;
WK_word compressionBuffer[4 * uncompressedWords];
WK_word decompressionBuffer[uncompressedWords];
// Get a compressed copy of the page so that the decompression can
// be timed.
returnPreDecompressionSize =
WKdm_compress((WK_word*)uncompressedData,
compressionBuffer,
uncompressedWords);
// 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
WKdm_decompress(compressionBuffer,
decompressionBuffer,
uncompressedWords);
//stop
clock_gettime(CLOCK_REALTIME, &stop);
accum = (stop.tv_sec - start.tv_sec)
+ (stop.tv_nsec - start.tv_nsec);
/// 1000000000.0;
returnDecompressionTime = accum;
//endstop
// Set the value that will return the decompression time.
//STOP_TIMER(returnDecompressionTime);
}