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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
/* Copyright (C) 2006 MySQL AB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
#include "azio.h"
#include <string.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <my_getopt.h>
#include <mysql_version.h>
#define ARCHIVE_ROW_HEADER_SIZE 4
#define COMMENT_STRING "Your bases"
#define FRM_STRING "My bases"
#define TEST_FILENAME "performance_test.az"
#define TEST_STRING_INIT "YOU don't know about me without you have read a book by the name of The Adventures of Tom Sawyer; but that ain't no matter. That book was made by Mr. Mark Twain, and he told the truth, mainly. There was things which he stretched, but mainly he told the truth. That is nothing. I never seen anybody but lied one time or another, without it was Aunt Polly, or the widow, or maybe Mary. Aunt Polly--Tom's Aunt Polly, she is--and Mary, and the Widow Douglas is all told about in that book, which is mostly a true book, with some stretchers, as I said before. Now the way that the book winds up is this: Tom and me found the money that the robbers hid in the cave, and it made us rich. We got six thousand dollars apiece--all gold. It was an awful sight of money when it was piled up. Well, Judge Thatcher he took it and put it out at interest, and it fetched us a dollar a day apiece all the year round --more than a body could tell what to do with. The Widow Douglas she took me for her son, and allowed she would..."
#define TEST_LOOP_NUM 100
#define ARCHIVE_ROW_HEADER_SIZE 4
#define BUFFER_LEN 1024
char test_string[BUFFER_LEN];
#define ROWS_TO_TEST LL(2000000)
/* prototypes */
long int timedif(struct timeval a, struct timeval b);
int generate_data(unsigned long long length);
int read_test(azio_stream *reader_handle, unsigned long long rows_to_test_for);
int main(int argc, char *argv[])
{
unsigned int method;
struct timeval start_time, end_time;
long int timing;
my_init();
MY_INIT(argv[0]);
if (argc != 1)
return 1;
printf("Performing write() test\n");
generate_data(ROWS_TO_TEST);
for (method= AZ_METHOD_BLOCK; method < AZ_METHOD_MAX; method++)
{
unsigned int ret;
azio_stream reader_handle;
if (method)
printf("Performing aio_read() test\n");
else
printf("Performing read() test\n");
if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY|O_BINARY,
method)))
{
printf("Could not open test file\n");
return 0;
}
gettimeofday(&start_time, NULL);
read_test(&reader_handle, 1044496L);
gettimeofday(&end_time, NULL);
timing= timedif(end_time, start_time);
printf("Time took to read was %ld.%03ld seconds\n", timing / 1000, timing % 1000);
azclose(&reader_handle);
}
my_end(0);
return 0;
}
int generate_data(unsigned long long rows_to_test)
{
azio_stream writer_handle;
unsigned long long x;
unsigned int ret;
struct timeval start_time, end_time;
long int timing;
struct stat buf;
if ((stat(TEST_FILENAME, &buf)) == 0)
{
printf("Writer file already available\n");
return 0;
}
if (!(ret= azopen(&writer_handle, TEST_FILENAME, O_CREAT|O_RDWR|O_TRUNC|O_BINARY,
AZ_METHOD_BLOCK)))
{
printf("Could not create test file\n");
exit(1);
}
gettimeofday(&start_time, NULL);
for (x= 0; x < rows_to_test; x++)
{
ret= azwrite_row(&writer_handle, test_string, BUFFER_LEN);
if (ret != BUFFER_LEN)
{
printf("Size %u\n", ret);
assert(ret != BUFFER_LEN);
}
if ((x % 14031) == 0)
{
azflush(&writer_handle, Z_SYNC_FLUSH);
}
}
/*
We put the flush in just to be honest with write speed, normally azclose
would be fine.
*/
azflush(&writer_handle, Z_SYNC_FLUSH);
gettimeofday(&end_time, NULL);
timing= timedif(end_time, start_time);
azclose(&writer_handle);
printf("Time took to write was %ld.%03ld seconds\n", timing / 1000, timing % 1000);
return 0;
}
int read_test(azio_stream *reader_handle, unsigned long long rows_to_test_for)
{
unsigned long long read_length= 0;
unsigned long long count= 0;
unsigned int ret;
int error;
azread_init(reader_handle);
while ((ret= azread_row(reader_handle, &error)))
{
if (error)
{
fprintf(stderr, "Got an error while reading at row %llu\n", count);
exit(1);
}
read_length+= ret;
assert(!memcmp(reader_handle->row_ptr, test_string, ret));
if (ret != BUFFER_LEN)
{
printf("Size %u\n", ret);
assert(ret != BUFFER_LEN);
}
count++;
}
assert(rows_to_test_for == rows_to_test_for);
return 0;
}
long int timedif(struct timeval a, struct timeval b)
{
register int us, s;
us = a.tv_usec - b.tv_usec;
us /= 1000;
s = a.tv_sec - b.tv_sec;
s *= 1000;
return s + us;
}
|