-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbittester.c
111 lines (99 loc) · 2.63 KB
/
bittester.c
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
#include <stdlib.h>
#include <stdio.h>
#include <sys/time.h>
#define VPXCODING_READER
#define VPXCODING_WRITER
#define VPXCODING_NOTABLE
#include "vpxcoding.h"
double GetAbsoluteTime()
{
struct timeval tv;
gettimeofday( &tv, 0 );
return ((double)tv.tv_usec)/1000000. + (tv.tv_sec);
}
uint8_t dummydata[1024*1024*16];
//#define TEST_RANDOM_PROBS
#ifndef TEST_RANDOM_PROBS
const int arbitrary_prob = 187;
#else
uint8_t dummyprobs[1024*1024*16*8];
#endif
int main( int argc, char ** argv )
{
int i;
#if 0
for( i = 0; i < 256; i++ )
{
printf( "%2d", VPXCODING_VPXNORM( i ) );
if( ( i & 15 ) == 15 )
{
printf( "\n" );
}
}
return 0;
#endif
for( i = 0; i < sizeof(dummydata); i++ )
{
//dummydata[i] = rand();
dummydata[i] = ((rand()&0xff)*(rand()&0xff)) >> 10;
}
vpx_writer w = { 0 };
uint8_t * bufferO = malloc(sizeof(dummydata)*20);
vpx_start_encode( &w, bufferO, sizeof(dummydata)*20);
double startEnc = GetAbsoluteTime();
int bitno = 0;
for( i = 0; i < sizeof(dummydata); i++ )
{
int data = dummydata[i];
int bits = 8;
int bit;
for (bit = bits - 1; bit >= 0; bit--)
{
#ifdef TEST_RANDOM_PROBS
int prob = dummyprobs[bitno++];
#else
int prob = arbitrary_prob;
#endif
int outbit = (data >> bit) & 1;
vpx_write(&w, outbit, prob);
}
}
vpx_stop_encode(&w);
double endEnc = GetAbsoluteTime();
printf( "Input Len: %ld bytes (%ld bits)\n", sizeof(dummydata), sizeof(dummydata) * 8 );
printf( "Output Len: %d (%d count) (Out of a maximum of %d bytes)\n", w.pos, w.count, w.size );
if( w.error )
{
fprintf( stderr, "Encoder reported %d\n", w.error );
return -10;
}
printf( "Error / Range: %d %d\n", w.error, w.range );
printf( "Relative Size: %.2f %%\n", w.pos * 100.0 / sizeof(dummydata) );
vpx_reader reader;
int ret = vpx_reader_init(&reader, bufferO, w.pos, 0, 0 );
double startDec = GetAbsoluteTime();
bitno = 0;
for( i = 0; i < sizeof(dummydata); i++ )
{
int bits = 8;
int bit;
uint8_t data = 0;
#ifdef TEST_RANDOM_PROBS
int prob = dummyprobs[bitno++] = rand()&0xff;
#else
int prob = arbitrary_prob;
#endif
for (bit = bits - 1; bit >= 0; bit--)// Arbitrary, for testing
data = (data<<1) | vpx_read(&reader, prob);
if( data != dummydata[i] )
{
fprintf( stderr, "Disagree at %d (%08x != %08x)\n", i, data, dummydata[i] );
return -9;
}
}
double endDec = GetAbsoluteTime();
printf( "Matching %d bytes\n", i );
printf( "Encode Time: %.3fms (%.3f MBytes/s)\n", (endEnc - startEnc)*1000.0, (sizeof(dummydata)/1024/1024)/(endEnc - startEnc) );
printf( "Decode Time: %.3fms (%.3f MBytes/s)\n", (endDec - startDec)*1000.0, (sizeof(dummydata)/1024/1024)/(endDec - startDec) );
return 0;
}