2 * hashtest.c -- test hash mapping
4 * Generate timing statistics for vertical-motion optimization.
6 * $Id: hashtest.c,v 1.14 1998/06/13 22:45:39 tom Exp $
10 #define Trace(p) _tracef p
13 #define Trace(p) /* nothing */
16 #include <test.priv.h>
25 static bool continuous = FALSE;
26 static bool reverse_loops = FALSE;
27 static bool single_step = FALSE;
28 static bool extend_corner = FALSE;
29 static int foot_lines = 0;
30 static int head_lines = 0;
32 static void cleanup(void)
40 static RETSIGTYPE finish(int sig GCC_UNUSED)
46 static void genlines(int base)
52 Trace(("Resetting screen"));
54 Trace(("Painting `%c' screen", base));
57 /* Do this so writes to lower-right corner don't cause a spurious
58 * scrolling operation. This _shouldn't_ break the scrolling
59 * optimization, since that's computed in the refresh() call.
61 scrollok(stdscr, FALSE);
64 for (i = 0; i < head_lines; i++)
65 for (j = 0; j < COLS; j++)
66 addch((j % 8 == 0) ? ('A' + j/8) : '-');
69 for (i = head_lines; i < LINES - foot_lines; i++) {
70 int c = (base - LO_CHAR + i) % (HI_CHAR - LO_CHAR + 1) + LO_CHAR;
71 int hi = (extend_corner || (i < LINES - 1)) ? COLS : COLS - 1;
72 for (j = 0; j < hi; j++)
76 for (i = LINES - foot_lines; i < LINES; i++) {
78 for (j = 0; j < (extend_corner ? COLS : COLS - 1); j++)
79 addch((j % 8 == 0) ? ('A' + j/8) : '-');
82 scrollok(stdscr, TRUE);
90 static void one_cycle(int ch)
94 } else if (ch != 'a') {
100 static void run_test(bool optimized)
103 int lo = continuous ? LO_CHAR : 'a' - LINES;
104 int hi = continuous ? HI_CHAR : 'a' + LINES;
111 #if defined(TRACE) || defined(NCURSES_TEST)
113 Trace(("With hash mapping"));
114 _nc_optimize_enable |= OPTIMIZE_HASHMAP;
116 Trace(("Without hash mapping"));
117 _nc_optimize_enable &= ~OPTIMIZE_HASHMAP;
122 for (ch = hi; ch >= lo; ch--)
125 for (ch = lo; ch <= hi; ch++)
129 static void usage(void)
131 static const char *const tbl[] = {
132 "Usage: hashtest [options]"
135 ," -c continuous (don't reset between refresh's)"
136 ," -f num leave 'num' lines constant for footer"
137 ," -h num leave 'num' lines constant for header"
138 ," -l num repeat test 'num' times"
139 ," -n test the normal optimizer"
140 ," -o test the hashed optimizer"
141 ," -r reverse the loops"
143 ," -x assume lower-right corner extension"
147 for (n = 0; n < sizeof(tbl)/sizeof(tbl[0]); n++)
148 fprintf(stderr, "%s\n", tbl[n]);
152 int main(int argc, char *argv[])
156 int test_normal = FALSE;
157 int test_optimize = FALSE;
159 while ((c = getopt(argc, argv, "cf:h:l:norsx")) != EOF) {
165 foot_lines = atoi(optarg);
168 head_lines = atoi(optarg);
171 test_loops = atoi(optarg);
177 test_optimize = TRUE;
180 reverse_loops = TRUE;
186 extend_corner = TRUE;
192 if (!test_normal && !test_optimize) {
194 test_optimize = TRUE;
200 (void) signal(SIGINT, finish); /* arrange interrupts to terminate */
202 (void) initscr(); /* initialize the curses library */
203 keypad(stdscr, TRUE); /* enable keyboard mapping */
204 (void) nonl(); /* tell curses not to do NL->CR/NL on output */
205 (void) cbreak(); /* take input chars one at a time, no wait for \n */
206 (void) noecho(); /* don't echo input */
207 scrollok(stdscr, TRUE);
209 while (test_loops-- > 0) {
216 cleanup(); /* we're done */
217 return(EXIT_SUCCESS);
219 /* hashtest.c ends here */