File: test.c

package info (click to toggle)
allegro4.4 2%3A4.4.3.1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 20,756 kB
  • sloc: ansic: 164,458; asm: 17,620; cpp: 3,848; javascript: 3,053; objc: 1,687; sh: 1,107; python: 676; pascal: 179; makefile: 57; perl: 29; lisp: 1
file content (109 lines) | stat: -rw-r--r-- 2,235 bytes parent folder | download | duplicates (7)
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
/*
 *	Benchmark test program for JPGalleg
 *
 *  Version 2.6, by Angelo Mottola, 2000-2006
 *
 *	This program tests the speed of the JPGalleg loading functions.
 */

#include <string.h>
#include <allegro.h>
#include <jpgalleg.h>


static volatile int timer = 0;


static void
about(void)
{
	printf(JPGALLEG_VERSION_STRING "\n"
		"Benchmark utility\n\n"
		"usage:\n"
		"\ttest [-f file] [times] [-nommx]\n\n"
		"-f file\t\tThe JPG image file to test with. If this is not specified, the\n"
		"\t\tprogram will try to use \"jpgalleg.jpg\" from the current dir.\n"
		"times\t\tNumber of times the test is repeated. Defaults to 30.\n"
		"-nommx\t\tDisables MMX optimizations before doing the test.\n\n"
	);
	exit(EXIT_FAILURE);
}


static void
timer_handler(void)
{
	timer++;
}
END_OF_FUNCTION(timer_handler);


int
main(int argc, char **argv)
{
	BITMAP *bmp;
	PACKFILE *f;
	char *file = NULL, *times = NULL, *memory = NULL;
	int arg, i, n, start, end, size;

	allegro_init();
	install_keyboard();
	install_timer();
	
	jpgalleg_init();
	
	set_color_conversion(COLORCONV_NONE);
	
	for (arg = 1; arg < argc; arg++) {
		if (!strcmp(argv[arg], "-nommx"))
			cpu_capabilities &= ~CPU_MMX;
		else if (!strcmp(argv[arg], "-f"))
			file = argv[++arg];
		else if (!times)
			times = argv[arg];
		else
			about();
	}
	if (times)
		n = atoi(times);
	else
		n = 30;
	if (!file)
		file = "jpgalleg.jpg";
	bmp = load_jpg(file, NULL);
	if (!bmp) {
		printf("Cannot find %s!\n", file);
		return -1;
	}
	size = file_size(file);
	memory = (char *)malloc(size);
	if (!memory) {
		printf("Not enough memory!\n");
		return -1;
	}
	f = pack_fopen(file, F_READ);
	pack_fread(memory, size, f);
	pack_fclose(f);
	
	LOCK_FUNCTION(timer_handler);
	LOCK_VARIABLE(timer);
	
	install_int(timer_handler, 10);
	
	printf("Average timing for %d function calls:\n", n);
	start = timer;
	for (i = 0; i < n; i++)
		bmp = load_jpg(file, NULL);
	end = timer;
	printf("load_jpg: %f seconds\n", ((float)end - (float)start) / 1000.0 / (float)n);

	start = timer;
	for (i = 0; i < n; i++)
		bmp = load_memory_jpg(memory, size, NULL);
	end = timer;
	printf("load_memory_jpg: %f seconds\n", ((float)end - (float)start) / 1000.0 / (float)n);
	
	free(memory);
	return 0;
}
END_OF_MAIN()