2 * hashtest.c -- test hash mapping
4 * Generate timing statistics for vertical-motion optimization.
6 * $Id: hashtest.c,v 1.22 2002/06/29 23:32:18 tom Exp $
10 #define Trace(p) _tracef p
13 #define Trace(p) /* nothing */
19 #include <test.priv.h>
24 static bool continuous = FALSE;
25 static bool reverse_loops = FALSE;
26 static bool single_step = FALSE;
27 static bool extend_corner = FALSE;
28 static int foot_lines = 0;
29 static int head_lines = 0;
41 finish(int sig GCC_UNUSED)
44 ExitProgram(EXIT_FAILURE);
54 Trace(("Resetting screen"));
56 Trace(("Painting `%c' screen", base));
59 /* Do this so writes to lower-right corner don't cause a spurious
60 * scrolling operation. This _shouldn't_ break the scrolling
61 * optimization, since that's computed in the refresh() call.
63 scrollok(stdscr, FALSE);
66 for (i = 0; i < head_lines; i++)
67 for (j = 0; j < COLS; j++)
68 addch((j % 8 == 0) ? ('A' + j / 8) : '-');
71 for (i = head_lines; i < LINES - foot_lines; i++) {
72 int c = (base - LO_CHAR + i) % (HI_CHAR - LO_CHAR + 1) + LO_CHAR;
73 int hi = (extend_corner || (i < LINES - 1)) ? COLS : COLS - 1;
74 for (j = 0; j < hi; j++)
78 for (i = LINES - foot_lines; i < LINES; i++) {
80 for (j = 0; j < (extend_corner ? COLS : COLS - 1); j++)
81 addch((j % 8 == 0) ? ('A' + j / 8) : '-');
84 scrollok(stdscr, TRUE);
97 } else if (ch != 'a') {
104 run_test(bool optimized GCC_UNUSED)
107 int lo = continuous ? LO_CHAR : 'a' - LINES;
108 int hi = continuous ? HI_CHAR : 'a' + LINES;
115 #if defined(TRACE) || defined(NCURSES_TEST)
117 Trace(("With hash mapping"));
118 _nc_optimize_enable |= OPTIMIZE_HASHMAP;
120 Trace(("Without hash mapping"));
121 _nc_optimize_enable &= ~OPTIMIZE_HASHMAP;
126 for (ch = hi; ch >= lo; ch--)
129 for (ch = lo; ch <= hi; ch++)
136 static const char *const tbl[] =
138 "Usage: hashtest [options]"
141 ," -c continuous (don't reset between refresh's)"
142 ," -f num leave 'num' lines constant for footer"
143 ," -h num leave 'num' lines constant for header"
144 ," -l num repeat test 'num' times"
145 ," -n test the normal optimizer"
146 ," -o test the hashed optimizer"
147 ," -r reverse the loops"
149 ," -x assume lower-right corner extension"
153 for (n = 0; n < SIZEOF(tbl); n++)
154 fprintf(stderr, "%s\n", tbl[n]);
155 ExitProgram(EXIT_FAILURE);
159 main(int argc, char *argv[])
163 int test_normal = FALSE;
164 int test_optimize = FALSE;
166 setlocale(LC_ALL, "");
168 while ((c = getopt(argc, argv, "cf:h:l:norsx")) != EOF) {
174 foot_lines = atoi(optarg);
177 head_lines = atoi(optarg);
180 test_loops = atoi(optarg);
186 test_optimize = TRUE;
189 reverse_loops = TRUE;
195 extend_corner = TRUE;
201 if (!test_normal && !test_optimize) {
203 test_optimize = TRUE;
209 (void) signal(SIGINT, finish); /* arrange interrupts to terminate */
211 (void) initscr(); /* initialize the curses library */
212 keypad(stdscr, TRUE); /* enable keyboard mapping */
213 (void) nonl(); /* tell curses not to do NL->CR/NL on output */
214 (void) cbreak(); /* take input chars one at a time, no wait for \n */
215 (void) noecho(); /* don't echo input */
216 scrollok(stdscr, TRUE);
218 while (test_loops-- > 0) {
225 cleanup(); /* we're done */
226 ExitProgram(EXIT_SUCCESS);
228 /* hashtest.c ends here */