encodespeed.c 1.47 KB
#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: