2 * hashtest.c -- test hash mapping
4 * Generate timing statistics for vertical-motion optimization.
6 * $Id: hashtest.c,v 1.8 1997/01/18 19:09:30 tom Exp $
12 #define Trace(p) _tracef p
15 #define Trace(p) /* nothing */
19 #include <test.priv.h>
28 static void finish(int sig) GCC_NORETURN;
30 static bool continuous = FALSE;
31 static bool reverse_loops = FALSE;
32 static bool extend_corner = FALSE;
33 static int foot_lines = 0;
34 static int head_lines = 0;
36 static void genlines(int base)
42 Trace(("Resetting screen"));
44 Trace(("Painting `%c' screen", base));
48 for (i = 0; i < head_lines; i++)
49 for (j = 0; j < COLS; j++)
50 addch((j % 8 == 0) ? ('A' + j/8) : '-');
53 for (i = head_lines; i < LINES - foot_lines; i++) {
54 int c = (base - LO_CHAR + i) % (HI_CHAR - LO_CHAR + 1) + LO_CHAR;
55 int hi = (extend_corner || (i < LINES - 1)) ? COLS : COLS - 1;
56 for (j = 0; j < hi; j++)
60 move(LINES - foot_lines, 0);
61 for (i = LINES - foot_lines; i < LINES; i++)
62 for (j = 0; j < extend_corner ? COLS : COLS - 1; j++)
63 addch((j % 8 == 0) ? ('A' + j/8) : '-');
67 static void one_cycle(int ch)
71 } else if (ch != 'a') {
77 static void run_test(bool optimized)
80 int lo = continuous ? LO_CHAR : 'a' - LINES;
81 int hi = continuous ? HI_CHAR : 'a' + LINES;
83 #ifdef NCURSES_VERSION
85 Trace(("With hash mapping"));
86 _nc_optimize_enable |= OPTIMIZE_HASHMAP;
88 Trace(("Without hash mapping"));
89 _nc_optimize_enable &= ~OPTIMIZE_HASHMAP;
94 for (ch = hi; ch >= lo; ch--)
97 for (ch = lo; ch <= hi; ch++)
101 static void usage(void)
103 static const char *const tbl[] = {
104 "Usage: hashtest [options]"
107 ," -c continuous (don't reset between refresh's)"
108 ," -f num leave 'num' lines constant for footer"
109 ," -h num leave 'num' lines constant for header"
110 ," -l num repeat test 'num' times"
111 ," -n test the normal optimizer"
112 ," -o test the hashed optimizer"
113 ," -r reverse the loops"
114 ," -x assume lower-right corner extension"
118 for (n = 0; n < sizeof(tbl)/sizeof(tbl[0]); n++)
119 fprintf(stderr, "%s\n", tbl[n]);
123 int main(int argc, char *argv[])
127 int test_normal = FALSE;
128 int test_optimize = FALSE;
130 while ((c = getopt(argc, argv, "cf:h:l:norx")) != EOF) {
136 foot_lines = atoi(optarg);
139 head_lines = atoi(optarg);
142 test_loops = atoi(optarg);
148 test_optimize = TRUE;
151 reverse_loops = TRUE;
154 extend_corner = TRUE;
160 if (!test_normal && !test_optimize) {
162 test_optimize = TRUE;
168 (void) signal(SIGINT, finish); /* arrange interrupts to terminate */
170 (void) initscr(); /* initialize the curses library */
171 keypad(stdscr, TRUE); /* enable keyboard mapping */
172 (void) nonl(); /* tell curses not to do NL->CR/NL on output */
173 (void) cbreak(); /* take input chars one at a time, no wait for \n */
174 (void) noecho(); /* don't echo input */
175 scrollok(stdscr, TRUE);
177 while (test_loops-- > 0) {
184 finish(0); /* we're done */
187 static RETSIGTYPE finish(int sig)
190 exit(sig != 0 ? EXIT_FAILURE : EXIT_SUCCESS);
193 /* hashtest.c ends here */