2 * hashtest.c -- test hash mapping
4 * Generate timing statistics for vertical-motion optimization.
6 * $Id: hashtest.c,v 1.12 1997/08/09 14:25:18 tom Exp $
12 #define Trace(p) _tracef p
15 #define Trace(p) /* nothing */
19 #include <test.priv.h>
28 static bool continuous = FALSE;
29 static bool reverse_loops = FALSE;
30 static bool single_step = FALSE;
31 static bool extend_corner = FALSE;
32 static int foot_lines = 0;
33 static int head_lines = 0;
35 static void cleanup(void)
43 static RETSIGTYPE finish(int sig GCC_UNUSED)
49 static void genlines(int base)
55 Trace(("Resetting screen"));
57 Trace(("Painting `%c' screen", base));
60 /* Do this so writes to lower-right corner don't cause a spurious
61 * scrolling operation. This _shouldn't_ break the scrolling
62 * optimization, since that's computed in the refresh() call.
64 scrollok(stdscr, FALSE);
67 for (i = 0; i < head_lines; i++)
68 for (j = 0; j < COLS; j++)
69 addch((j % 8 == 0) ? ('A' + j/8) : '-');
72 for (i = head_lines; i < LINES - foot_lines; i++) {
73 int c = (base - LO_CHAR + i) % (HI_CHAR - LO_CHAR + 1) + LO_CHAR;
74 int hi = (extend_corner || (i < LINES - 1)) ? COLS : COLS - 1;
75 for (j = 0; j < hi; j++)
79 for (i = LINES - foot_lines; i < LINES; i++) {
81 for (j = 0; j < (extend_corner ? COLS : COLS - 1); j++)
82 addch((j % 8 == 0) ? ('A' + j/8) : '-');
85 scrollok(stdscr, TRUE);
93 static void one_cycle(int ch)
97 } else if (ch != 'a') {
103 static void run_test(bool optimized)
106 int lo = continuous ? LO_CHAR : 'a' - LINES;
107 int hi = continuous ? HI_CHAR : 'a' + LINES;
109 #ifdef NCURSES_VERSION
111 Trace(("With hash mapping"));
112 _nc_optimize_enable |= OPTIMIZE_HASHMAP;
114 Trace(("Without hash mapping"));
115 _nc_optimize_enable &= ~OPTIMIZE_HASHMAP;
120 for (ch = hi; ch >= lo; ch--)
123 for (ch = lo; ch <= hi; ch++)
127 static void usage(void)
129 static const char *const tbl[] = {
130 "Usage: hashtest [options]"
133 ," -c continuous (don't reset between refresh's)"
134 ," -f num leave 'num' lines constant for footer"
135 ," -h num leave 'num' lines constant for header"
136 ," -l num repeat test 'num' times"
137 ," -n test the normal optimizer"
138 ," -o test the hashed optimizer"
139 ," -r reverse the loops"
141 ," -x assume lower-right corner extension"
145 for (n = 0; n < sizeof(tbl)/sizeof(tbl[0]); n++)
146 fprintf(stderr, "%s\n", tbl[n]);
150 int main(int argc, char *argv[])
154 int test_normal = FALSE;
155 int test_optimize = FALSE;
157 while ((c = getopt(argc, argv, "cf:h:l:norsx")) != EOF) {
163 foot_lines = atoi(optarg);
166 head_lines = atoi(optarg);
169 test_loops = atoi(optarg);
175 test_optimize = TRUE;
178 reverse_loops = TRUE;
184 extend_corner = TRUE;
190 if (!test_normal && !test_optimize) {
192 test_optimize = TRUE;
198 (void) signal(SIGINT, finish); /* arrange interrupts to terminate */
200 (void) initscr(); /* initialize the curses library */
201 keypad(stdscr, TRUE); /* enable keyboard mapping */
202 (void) nonl(); /* tell curses not to do NL->CR/NL on output */
203 (void) cbreak(); /* take input chars one at a time, no wait for \n */
204 (void) noecho(); /* don't echo input */
205 scrollok(stdscr, TRUE);
207 while (test_loops-- > 0) {
214 cleanup(); /* we're done */
215 return(EXIT_SUCCESS);
217 /* hashtest.c ends here */