home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / c / quikc21.zip / QBENCH.C < prev    next >
Text File  |  1989-07-06  |  13KB  |  436 lines

  1. /*===========================================================================*\
  2. | QBENCH.C                                                  ver 2.1, 07-06-89 |
  3. |                                                                             |
  4. | Produces a "screens/second" table for QWIKC Screen Utilities.               |
  5. |                                                                             |
  6. | I'm not trying to support this program, so don't expect it to be            |
  7. | perfect.  It will just give you a good feel for speed.  The time is         |
  8. | adjusted for an average 8 second test for each condition - total of 56      |
  9. | seconds.  For more accurate results, change test_time to 16.  Or for a      |
  10. | quicker but less accurate test, change test_time to 2.                      |
  11. | Be sure to see how fast virtual screens are!                                |
  12. | Also try this out in a multi-tasking environment.                           |
  13. | Test is for 80x25 screens only.                                             |
  14. |                                                                             |
  15. |  Copyright (c) 1988,1989 by James H. LeMay, All rights reserved.            |
  16. |                                                                             |
  17. |  Conversion to C by Jordan Gallagher / Wisdom Research                      |
  18. \*===========================================================================*/
  19.  
  20. #include <stdio.h>
  21. #include <conio.h>
  22. #include <string.h>
  23. #include <ctype.h>
  24. #include <process.h>
  25. #include <stdlib.h>
  26.  
  27. #include "qwikc21.h"
  28. #include "timerd12.h"
  29.  
  30. enum attrs {
  31.     attr,
  32.     noattr
  33. };
  34.  
  35. enum procs {
  36.     qwrites,
  37.     qfills,
  38.     qattrs,
  39.     qstores,
  40.     qscrolls
  41. };
  42.  
  43. #define test_time 8  /* test time in seconds for each case.  8 gives +/- 1% */
  44.  
  45. int      attrib;
  46. int      count;
  47. unsigned screens;
  48. char     row;
  49. char     col;
  50. char     rows;
  51. char     cols;
  52. float    scrpersec[5][2];
  53. char     strng[81];
  54. int      proc;
  55. int      a;
  56. FILE     *fv;
  57. int      todisk;
  58. int      tovirtual;
  59. char     ch;
  60. vscr_t   oldscr;
  61. unsigned scr1[4000];
  62. unsigned scr2[4000];
  63.  
  64. char names[5][80] =
  65. { " qwrite-     ", " qfill-      ", " qattr-      ",
  66.   " qstore-     ", " qscroll-    " };
  67.  
  68.  
  69. /******************************| check_zenith |*****************************\
  70. Since Zenith doesn't have snow on any CGAs, turn off snow checking.
  71. \***************************************************************************/
  72. void check_zenith(void)
  73. {
  74.     char tmp[10];
  75.  
  76.     movedata( 0xF000u, 0x800Cu, (unsigned)(((char far *)tmp)+1),
  77.                                 (unsigned)((char far *)tmp),     8 );
  78.     if(qsnow && (strncmp( tmp, "ZDS CORP", 8 )) == 0) {
  79.         qsnow=0;
  80.         cardsnow=0;
  81.     }
  82. }
  83.  
  84.  
  85. /********************************| clearscr |*******************************\
  86. Clears the screen using the yellow on black attribute.
  87. \***************************************************************************/
  88. void clearscr(void)
  89. {
  90.     qfill( 1, 1, crt_rows, crt_cols, WHITE+BLUE_BG, ' ' );
  91. }
  92.  
  93.  
  94. /*******************************| timertest |*******************************\
  95. Clears the screen using the yellow on black attribute.
  96. \***************************************************************************/
  97. void timertest(void)
  98. {
  99.     unsigned char tests=0;
  100.  
  101.     timer( T_START );
  102.     do {
  103.         for(count=0; count<screens; count++)
  104.             for(row=1; row<=25; row++)
  105.                 qwrite( row, 1, YELLOW, strng );
  106.         timer(T_STOP);
  107.         tests++;
  108.     } while( elapsed_time < 1.0 );
  109.     screens = screens*tests*test_time/elapsed_time;
  110. }
  111.  
  112. /********************************| checktime |******************************\
  113. Checks the timer.
  114. \***************************************************************************/
  115. void check_time(void)
  116. {
  117.     char str2[81];
  118.  
  119.     if(qsnow)
  120.          screens=8;        /* First guess for screens for 1 second test */
  121.     else screens=80;
  122.     if(tovirtual)
  123.         screens=2;
  124.  
  125.     strcpy( str2, "TimerTest " );
  126.     for(count=0; count < 8; count++) {         /* copy 8 times */
  127.         strcat( strng, str2 );
  128.     }
  129.     timertest();
  130. }
  131.  
  132.  
  133. /*****************************| assemble_strng |****************************\
  134. Sets up a string for displaying based on the functions which are currently
  135. being tested, and whether or not they are writing using attributes.
  136. \***************************************************************************/
  137. void assemble_strng( int proc, int attrib )
  138. {
  139.     strcpy( strng, names[proc] );
  140.  
  141.     if(qsnow) {
  142.         strcat( strng, " Wait    " );
  143.     } else {
  144.         strcat( strng, " No Wait " );
  145.     }
  146.  
  147.     if(attrib == SAMEATTR) {
  148.         strcat( strng, " No Attr " );
  149.     } else {
  150.         strcat( strng, " w/ Attr " );
  151.     }
  152.  
  153.     memset( &strng[31], proc+49, 49 );
  154.     strng[80]=0;                             /* null-terminate */
  155. }
  156.  
  157.  
  158. /******************************| time_writing |*****************************\
  159. Times screen writes and fills.
  160. \***************************************************************************/
  161. void time_writing( int proc, int attrib )
  162. {
  163.     int a;
  164.  
  165.     clearscr();
  166.  
  167.     if(attrib == SAMEATTR) {
  168.         qattr( 1, 1, crt_rows, crt_cols, LIGHTGRAY );
  169.         a=noattr;
  170.     } else a=attr;
  171.  
  172.     assemble_strng( proc, attrib );
  173.  
  174.     switch(proc) {
  175.         case qwrites:
  176.             timer( T_START );
  177.  
  178.             for(count=1; count <= screens; count++)
  179.                 for(row=1; row <= 25; row++)
  180.                     qwrite( row, 1, attrib, strng );
  181.  
  182.             timer( T_STOP ); break;
  183.  
  184.         case qfills:
  185.             timer( T_START );
  186.  
  187.             for(count=1; count <= screens; count++)
  188.                 qfill( 1, 1, 25, 80, attrib, 'f' );
  189.  
  190.             timer( T_STOP ); break;
  191.  
  192.         case qattrs:
  193.             qfill( 1, 1, 25, 80, attrib, 'a' );
  194.             timer( T_START );
  195.  
  196.             for(count=1; count <= screens; count++)
  197.                 qattr( 1, 1, 25, 80, attrib );
  198.  
  199.             timer( T_STOP ); break;
  200.     }
  201.  
  202.     if(elapsed_time != 0.0)
  203.         scrpersec[proc][a] = screens / elapsed_time;
  204. }
  205.  
  206.  
  207. /*******************************| time_moving |*****************************\
  208. Times screen block moves.
  209. \***************************************************************************/
  210. void time_moving( int proc, int attrib )
  211. {
  212.     assemble_strng( proc, attrib );
  213.  
  214.     for(row=1; row <= 25; row++)
  215.         qwrite( row, 1, attrib, strng );
  216.  
  217.     switch(proc) {
  218.         case qstores:
  219.             timer( T_START );
  220.  
  221.             for(count=1; count <= screens; count++)
  222.                 qstoretomem( 1, 1, 25, 80, scr2 );
  223.  
  224.             timer( T_STOP ); break;
  225.  
  226.         case qscrolls:
  227.             timer( T_START );
  228.  
  229.             for(count=1; count <= screens; count++)
  230.                 qscrollup( 1, 1, 25, 80, SAMEATTR );
  231.  
  232.             timer( T_STOP ); break;
  233.     }
  234.  
  235.     scrpersec[proc][attr] = screens / elapsed_time;
  236. }
  237.  
  238.  
  239. /*******************************| getchoice |*******************************\
  240. Gets input from user.
  241. \***************************************************************************/
  242. char getchoice( char *msg, char answer1, char answer2 )
  243. {
  244.     clearscr();
  245.     qwritec( 12, 1, crt_cols, SAMEATTR, msg );
  246.     gotoeos();
  247. #ifdef __TURBOC__
  248.     while((ch=toupper(getch())) != answer1 && ch != answer2 && ch != 13);
  249. #else
  250.     while((ch=getch(),ch=toupper(ch)) != answer1 && ch != answer2 && ch != 13);
  251. #endif
  252.     return(ch==answer2);
  253. }
  254.  
  255.  
  256. /**********************************| init |*********************************\
  257. Initialize QBENCH.
  258. \***************************************************************************/
  259. void init(void)
  260. {
  261.     qinit();
  262.     check_zenith();
  263.     setmultitask();
  264. #ifdef __TURBOC__
  265.     if(inmultask) directvideo=0;
  266.     textattr(WHITE+BLUE_BG);
  267. #endif
  268.     clearscr();
  269. }
  270.  
  271.  
  272. /******************************| askquestions |*****************************\
  273. \***************************************************************************/
  274. void askquestions(void)
  275. {
  276.     if(qsnow) {
  277.         qsnow=0;
  278.  
  279.         do {
  280.             do {
  281.                 qattr( 1, 1, 10, 80, WHITE+BLUE_BG );
  282.                 qwritec( 12, 1, 80, -1, "Do you see "
  283.                          "snow anywhere on the screen? [Y/N]?" );
  284.                 gotoeos();
  285.             } while(!kbhit());
  286. #ifdef __TURBOC__
  287.             ch=toupper(getch());
  288. #else
  289.             ch=getch(); ch=toupper(ch);
  290. #endif
  291.         } while( !strchr( "YN", ch ) );
  292.  
  293.         if(ch == 'Y') {
  294.             qsnow=1;
  295.         } else {
  296.             clearscr();
  297.             qwritec( 10, 1, 80, -1,
  298.             "Congratulations!  You have a card better" );
  299.             qwritec( 11, 1, 80, -1, "than the standard IBM CGA." );
  300.             qwritec( 12, 1, 80, -1,
  301.             "However, to make it faster, you will need" );
  302.             qwritec( 13, 1, 80, -1, "to set qsnow to 0 manually." );
  303.             qwritec( 14, 1, 80, -1, "Please contact us about this." );
  304.             qwritec( 16, 1, 80, -1, "Press any key ...");
  305.  
  306.             gotorc( 16, 49 );
  307.             if( (ch=getch()) == 0 ) ch=getch();
  308.         }
  309.     }
  310.     tovirtual = getchoice( "Normal or Virtual screen [N/v]? ", 'N', 'V' );
  311.     todisk    = getchoice( "Data to Screen or Disk [S/d]? "  , 'S', 'D' );
  312.     modcursor(cursor_off);
  313.     clearscr();
  314.     oldscr = qscr;
  315. }
  316.  
  317.  
  318. /********************************| runtests |*******************************\
  319. \***************************************************************************/
  320. void runtests(void)
  321. {
  322.     if(tovirtual) {
  323.         sprintf( strng, "Please wait %d seconds ...", 7*test_time );
  324.         qwritec( 12, 1, crt_cols, SAMEATTR, strng );
  325.         qscrptr = scr1;
  326.         qsnow   = 0;
  327.     }
  328.     check_time();
  329.     time_writing( qwrites,  YELLOW+BLUE_BG );
  330.     time_writing( qwrites,  SAMEATTR       );
  331.     time_writing( qfills,   YELLOW+BLUE_BG );
  332.     time_writing( qfills,   SAMEATTR       );
  333.     time_writing( qattrs,   YELLOW+BLUE_BG );
  334.     time_moving(  qstores,  YELLOW+BLUE_BG );
  335.     time_moving(  qscrolls, YELLOW+BLUE_BG );
  336. }
  337.  
  338.  
  339. /******************************| printresults |*****************************\
  340. \***************************************************************************/
  341. void printresults(void)
  342. {
  343.     qscr=oldscr;
  344.     clearscr();
  345.  
  346.     if(todisk)
  347.          fv = fopen( "qbench.dta", "wt" );
  348.     else fv = stdout;
  349.  
  350.     gotorc( 1, 1 );
  351.     fprintf( fv, "S C R E E N S / S E C O N D\n" );
  352.     fprintf( fv, "             Chng\n" );
  353.     fprintf( fv, "Function     Attr S/sec  Typical for these functions:\n" );
  354.     fprintf( fv, "---------    ---- -----  --------------------------------"
  355.                  "---------------------\n" );
  356.  
  357.     for(proc=qwrites; proc <= qfills; proc++) {
  358.         for(a=attr; a <= noattr; a++) {
  359.             if(a == attr) {
  360.                 fprintf( fv, names[proc] );
  361.             } else {
  362.                 fprintf( fv, "             " );
  363.             }
  364.  
  365.             if(a == attr) {
  366.                 fprintf( fv, "Yes " );
  367.             } else {
  368.                 fprintf( fv, "No  " );
  369.             }
  370.  
  371.             fprintf( fv, "%6.1f  ", scrpersec[proc][a] );
  372.  
  373.             if(a == attr) {
  374.                 if(proc == qwrites) {
  375.                     fprintf( fv,
  376.                     "qwrite, qwritec, qwriteeos, qwrite_sub, "
  377.                     "qwriteeos_sub\n" );
  378.                 } else
  379.                 if(proc == qfills) {
  380.                     fprintf( fv, "qfill, qfillc, qfilleos\n" );
  381.                 }
  382.             } else fprintf( fv, "\n" );
  383.         }
  384.     }
  385.  
  386.     for(proc=qattrs; proc <= qscrolls; proc++) {
  387.         fprintf( fv, "%s", names[proc] );
  388.  
  389.         if(proc == qattrs) {
  390.             fprintf( fv, "Yes  " );
  391.         } else {
  392.             fprintf( fv, "n/a  " );
  393.         }
  394.  
  395.         fprintf( fv, "%5.1f  ", scrpersec[proc][attr] );
  396.  
  397.         switch(proc) {
  398.             case qattrs:
  399.                 fprintf( fv, "qattr, qattreos\n" ); break;
  400.  
  401.             case qstores:
  402.                 fprintf( fv,
  403.                 "qstoretomem, qstoretoscr, qscrtovscr, qvscrtoscr\n" ); break;
  404.  
  405.             case qscrolls:
  406.                 fprintf( fv, "qscrollup, qscrolldown\n" );
  407.         }
  408.     }
  409.  
  410.     gotorc( 13, 1 );
  411.  
  412.     fprintf( fv, "System ID        = 0x%X\n", system_id );
  413.     fprintf( fv, "CPU ID           = %d\n", cpuid );
  414.     fprintf( fv, "Wait-for-retrace = %d\n", qsnow );
  415.     fprintf( fv, "Virtual screen   = %d\n", tovirtual );
  416.     fprintf( fv, "Screens/test     = %d\n", screens );
  417.  
  418.     fclose( fv );
  419.     gotorc( 24, 1 );
  420.     setcursor( cursor_initial );
  421. }
  422.  
  423.  
  424. /**********************************| main |*********************************\
  425. Main block.
  426. \***************************************************************************/
  427. void main(void)
  428. {
  429.     init();
  430.  
  431.     askquestions();
  432.     runtests();
  433.     printresults();
  434. }
  435.  
  436.