2 * hashtest.c -- test hash mapping
4 * Generate timing statistics for vertical-motion optimization.
6 * $Id: hashtest.c,v 1.15 2000/09/02 19:23:33 tom Exp $
10 #define Trace(p) _tracef p
13 #define Trace(p) /* nothing */
17 #include <test.priv.h>
26 static bool continuous = FALSE;
27 static bool reverse_loops = FALSE;
28 static bool single_step = FALSE;
29 static bool extend_corner = FALSE;
30 static int foot_lines = 0;
31 static int head_lines = 0;
33 static void cleanup(void)
41 static RETSIGTYPE finish(int sig GCC_UNUSED)
47 static void genlines(int base)
53 Trace(("Resetting screen"));
55 Trace(("Painting `%c' screen", base));
58 /* Do this so writes to lower-right corner don't cause a spurious
59 * scrolling operation. This _shouldn't_ break the scrolling
60 * optimization, since that's computed in the refresh() call.
62 scrollok(stdscr, FALSE);
65 for (i = 0; i < head_lines; i++)
66 for (j = 0; j < COLS; j++)
67 addch((j % 8 == 0) ? ('A' + j/8) : '-');
70 for (i = head_lines; i < LINES - foot_lines; i++) {
71 int c = (base - LO_CHAR + i) % (HI_CHAR - LO_CHAR + 1) + LO_CHAR;
72 int hi = (extend_corner || (i < LINES - 1)) ? COLS : COLS - 1;
73 for (j = 0; j < hi; j++)
77 for (i = LINES - foot_lines; i < LINES; i++) {
79 for (j = 0; j < (extend_corner ? COLS : COLS - 1); j++)
80 addch((j % 8 == 0) ? ('A' + j/8) : '-');
83 scrollok(stdscr, TRUE);
91 static void one_cycle(int ch)
95 } else if (ch != 'a') {
101 static void run_test(bool optimized)
104 int lo = continuous ? LO_CHAR : 'a' - LINES;
105 int hi = continuous ? HI_CHAR : 'a' + LINES;
112 #if defined(TRACE) || defined(NCURSES_TEST)
114 Trace(("With hash mapping"));
115 _nc_optimize_enable |= OPTIMIZE_HASHMAP;
117 Trace(("Without hash mapping"));
118 _nc_optimize_enable &= ~OPTIMIZE_HASHMAP;
123 for (ch = hi; ch >= lo; ch--)
126 for (ch = lo; ch <= hi; ch++)
130 static void usage(void)
132 static const char *const tbl[] = {
133 "Usage: hashtest [options]"
136 ," -c continuous (don't reset between refresh's)"
137 ," -f num leave 'num' lines constant for footer"
138 ," -h num leave 'num' lines constant for header"
139 ," -l num repeat test 'num' times"
140 ," -n test the normal optimizer"
141 ," -o test the hashed optimizer"
142 ," -r reverse the loops"
144 ," -x assume lower-right corner extension"
148 for (n = 0; n < sizeof(tbl)/sizeof(tbl[0]); n++)
149 fprintf(stderr, "%s\n", tbl[n]);
153 int main(int argc, char *argv[])
157 int test_normal = FALSE;
158 int test_optimize = FALSE;
160 while ((c = getopt(argc, argv, "cf:h:l:norsx")) != EOF) {
166 foot_lines = atoi(optarg);
169 head_lines = atoi(optarg);
172 test_loops = atoi(optarg);
178 test_optimize = TRUE;
181 reverse_loops = TRUE;
187 extend_corner = TRUE;
193 if (!test_normal && !test_optimize) {
195 test_optimize = TRUE;
201 (void) signal(SIGINT, finish); /* arrange interrupts to terminate */
203 (void) initscr(); /* initialize the curses library */
204 keypad(stdscr, TRUE); /* enable keyboard mapping */
205 (void) nonl(); /* tell curses not to do NL->CR/NL on output */
206 (void) cbreak(); /* take input chars one at a time, no wait for \n */
207 (void) noecho(); /* don't echo input */
208 scrollok(stdscr, TRUE);
210 while (test_loops-- > 0) {
217 cleanup(); /* we're done */
218 return(EXIT_SUCCESS);
220 /* hashtest.c ends here */