encodespeed.c
1.47 KB
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
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <time.h>
#define URL "http%3A%2F%2ffoo+bar%2fabcd"
#define TIMES 10000000
#include "tr/hexencode.h"
int
main(int argc, char * argv[])
{
char buf[sizeof(URL)];
size_t new_size;
size_t hexsize = (sizeof(URL)-1) * 2;
char hexbuf[hexsize+1];
char hexbuf2[hexsize+1];
clock_t start, end;
int i;
printf("Some transformations of %s\n\n", URL);
printf("urlencode %d times ... ", TIMES);
start = clock();
for (i=0; i<TIMES; i++) {
memcpy(buf, URL, sizeof(URL));
new_size = TR_urldecode(buf, sizeof(URL)-1);
}
end = clock();
buf[new_size] = 0;
printf("done\nResult: (%zu)%s\n", new_size, buf);
printf("CPU time used: %f\n", (double)(end-start)/CLOCKS_PER_SEC);
puts("--------------------");
printf("hexencode %d times ... ", TIMES);
start = clock();
for (i=0; i<TIMES; i++) {
TR_hexencode(hexbuf, URL, sizeof(URL)-1);
}
end = clock();
hexbuf[hexsize] = hexbuf2[hexsize] = 0;
printf("done\nResult: %s\n", hexbuf);
printf("CPU time used: %f\n", (double)(end-start)/CLOCKS_PER_SEC);
puts("--------------------");
printf("hexdecode %d times ... ", TIMES);
start = clock();
for (i=0; i<TIMES; i++) {
memcpy(hexbuf2, hexbuf, hexsize);
new_size = TR_hexdecode(hexbuf2, hexsize);
}
end = clock();
hexbuf2[new_size] = 0;
printf("done\nResult: (%zu)%s\n", new_size, hexbuf2);
printf("CPU time used: %f\n", (double)(end-start)/CLOCKS_PER_SEC);
return 0;
}
// vim: set ft=c ts=4 sw=4: