home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / CLIPPER / CASEVS.ZIP / CASEVSIF.TXT
Text File  |  1994-03-01  |  45KB  |  1,205 lines

  1. /*
  2.    Program:            CaseVsIf
  3.  
  4.    Author:             Dan G. Applewhite
  5.  
  6.    Written:            February 28, 1994
  7.  
  8.    Purpose:            To test the claim by Boris Borzic (in the
  9.                        March 1994 issue of Reference Clipper)
  10.                        that DO CASE...ENDCASE is faster than
  11.                        IF...ELSE...ENDIF.
  12.  
  13.                        Phase 1 compares the total time required to
  14.                        reach the same condition in both structures
  15.                        and then exit the structure.  (I state it
  16.                        this way because Phase 1 cannot recognize
  17.                        whether the difference in times for the
  18.                        two structures is the "seek" time or the
  19.                        "exit" time or a combination of both.)
  20.  
  21.                        Phase 2 compares the point-to-point times
  22.                        for the two structures; that is, how much
  23.                        time elapses from evaluating one condition
  24.                        to evaluating the next condition.
  25.  
  26.                        Phase 3 compares the "seek" times of both
  27.                        structures and the "exit" times of both
  28.                        structures; that is, how long it takes to
  29.                        stop at the .T. condition and how long
  30.                        it takes to then exit from the structure.
  31.                        It also compares the total of the "seek"
  32.                        and "exit" times (which need not necessarily
  33.                        correspond to the Phase 1 time because the
  34.                        Phase 1 test involves only conditions,
  35.                        whereas the Phase 3 test involves those
  36.                        same conditions _plus_ actions).
  37.  
  38.    Compiler Used:      Clipper 5.2c        // switches /n /es2 /w
  39.  
  40.    Linker Used:        .RTLink 3.14B
  41.  
  42.    This program is an orginal work by Dan G. Applewhite and is
  43.    hereby placed into the public domain.
  44. */
  45.  
  46. #include "inkey.ch"
  47.  
  48. #define CRLF          ( Chr( 13 ) + Chr( 10 ) )
  49.  
  50. #define MAX_ITERS     1000
  51.  
  52. #define MIN_SECONDS   0.10
  53.  
  54. #define BUMP_UP_RATE  1.67
  55.  
  56. // Changing COND_COUNT would require also changing several
  57. // DO CASE...ENDCASE and IF...ELSE...ENDIF structures
  58. // throughout the program plus the #defines below.
  59.  
  60. #define COND_COUNT    25
  61.  
  62. // Adjust the following #defines to determine the type of
  63. // conditions to be evaluated.  Different conditions may
  64. // give surprisingly differents timing results!
  65.  
  66. // #define USING_NUMBERS
  67.  
  68. #ifdef USING_NUMBERS
  69.  
  70. // #define NEXPR + 64
  71.    #define NEXPR
  72.  
  73.    #define C1     1 NEXPR
  74.    #define C2     2 NEXPR
  75.    #define C3     3 NEXPR
  76.    #define C4     4 NEXPR
  77.    #define C5     5 NEXPR
  78.    #define C6     6 NEXPR
  79.    #define C7     7 NEXPR
  80.    #define C8     8 NEXPR
  81.    #define C9     9 NEXPR
  82.    #define C10   10 NEXPR
  83.    #define C11   11 NEXPR
  84.    #define C12   12 NEXPR
  85.    #define C13   13 NEXPR
  86.    #define C14   14 NEXPR
  87.    #define C15   15 NEXPR
  88.    #define C16   16 NEXPR
  89.    #define C17   17 NEXPR
  90.    #define C18   18 NEXPR
  91.    #define C19   19 NEXPR
  92.    #define C20   20 NEXPR
  93.    #define C21   21 NEXPR
  94.    #define C22   22 NEXPR
  95.    #define C23   23 NEXPR
  96.    #define C24   24 NEXPR
  97.    #define XCOND nCond NEXPR
  98.  
  99. #else
  100.  
  101. // #define NEXPR + 64
  102.    #define NEXPR
  103. // #define CEXPR + " extra characters "
  104.    #define CEXPR
  105.  
  106.    #define C1    Chr(  1 NEXPR ) CEXPR
  107.    #define C2    Chr(  2 NEXPR ) CEXPR
  108.    #define C3    Chr(  3 NEXPR ) CEXPR
  109.    #define C4    Chr(  4 NEXPR ) CEXPR
  110.    #define C5    Chr(  5 NEXPR ) CEXPR
  111.    #define C6    Chr(  6 NEXPR ) CEXPR
  112.    #define C7    Chr(  7 NEXPR ) CEXPR
  113.    #define C8    Chr(  8 NEXPR ) CEXPR
  114.    #define C9    Chr(  9 NEXPR ) CEXPR
  115.    #define C10   Chr( 10 NEXPR ) CEXPR
  116.    #define C11   Chr( 11 NEXPR ) CEXPR
  117.    #define C12   Chr( 12 NEXPR ) CEXPR
  118.    #define C13   Chr( 13 NEXPR ) CEXPR
  119.    #define C14   Chr( 14 NEXPR ) CEXPR
  120.    #define C15   Chr( 15 NEXPR ) CEXPR
  121.    #define C16   Chr( 16 NEXPR ) CEXPR
  122.    #define C17   Chr( 17 NEXPR ) CEXPR
  123.    #define C18   Chr( 18 NEXPR ) CEXPR
  124.    #define C19   Chr( 19 NEXPR ) CEXPR
  125.    #define C20   Chr( 20 NEXPR ) CEXPR
  126.    #define C21   Chr( 21 NEXPR ) CEXPR
  127.    #define C22   Chr( 22 NEXPR ) CEXPR
  128.    #define C23   Chr( 23 NEXPR ) CEXPR
  129.    #define C24   Chr( 24 NEXPR ) CEXPR
  130.  
  131.    // Important: Do not begin XCOND with "(" because doing
  132.    // so would cause a compile error on the IF structures.
  133.  
  134.    #define XCOND Chr( nCond NEXPR ) CEXPR
  135.  
  136. #endif
  137.  
  138. #xtranslate STRINGIFY( <exp> ) => #<exp>
  139.  
  140. /*
  141.    CaseVsIf() calls other routines which do the actual comparisons.
  142.    (It stands for "CASE versus IF".)
  143. */
  144. FUNCTION CaseVsIf( cMaxIters, cMinSecs )
  145.  
  146.    LOCAL nMaxIters := ;
  147.       If( cMaxIters == NIL, MAX_ITERS, Val( cMaxIters ) )
  148.    LOCAL nMinSecs := ;
  149.       If( cMinSecs == NIL, MIN_SECONDS, ;
  150.       Val( Str( Val( cMinSecs ), 5, 2 ) ) )
  151.    LOCAL nMax1 := 0, nMax2 := 0, nMax3 := 0, lGoodTest := .F.
  152.  
  153.    SET SCOREBOARD OFF
  154.  
  155.    OutStd( CRLF )
  156.    OutStd( CRLF )
  157.    OutStd( "CaseVsIf: A Utility for Comparing execution times" )
  158.    OutStd( CRLF )
  159.    OutStd( "of the multi-branch decision structures:" )
  160.    OutStd( CRLF )
  161.    OutStd( CRLF )
  162.    OutStd( "DO CASE...ENDCASE versus IF...ELSE...ENDIF" )
  163.    OutStd( CRLF )
  164.    OutStd( CRLF )
  165.    OutStd( "For phases 1 and 3, " )
  166.    OutStd( "conditions are " )
  167.  
  168. #ifdef USING_NUMBERS
  169.    OutStd( "numeric" )
  170. #else
  171.    OutStd( "character" )
  172. #endif
  173.  
  174.    OutStd( " comparisons, such as:" )
  175.    OutStd( CRLF )
  176.    OutStd( CRLF )
  177.    OutStd( Space( 3 ), STRINGIFY( XCOND ), "== ;" )
  178.    OutStd( CRLF )
  179.    OutStd( Space( 3 ), STRINGIFY( C1 ) )
  180.  
  181.    OutStd( CRLF )
  182.    OutStd( CRLF )
  183.    OutStd( "Starting nMaxIters value:", nMaxIters )
  184.    OutStd( CRLF )
  185.    OutStd( "Minimum number of seconds for all results:", nMinSecs )
  186.  
  187.    OutStd( CRLF )
  188.  
  189.    // Repeat the test until all three phases are using the
  190.    // same number of iterations while also meeting the
  191.    // minimum-seconds requirement.
  192.  
  193.    WHILE !lGoodTest ;
  194.    .AND. !( InKey() == K_ESC .AND. LastKey() == K_ESC )
  195.  
  196.       //  Compare condition "seek" + "exit" total time
  197.       nMax1 := Phase1( nMaxIters, nMinSecs )
  198.       nMaxIters := Max( nMax1, nMaxIters )
  199.  
  200.       //  Compare condition "stepping" time during "seek"
  201.       nMax2 := Phase2( nMaxIters, nMinSecs )
  202.       nMaxIters := Max( nMax1, nMaxIters )
  203.  
  204.       //  Compare condition "seek" and "exit" times separately
  205.       //  and also compare the sum of "seek" and "exit" times
  206.       nMax3 := Phase3( nMaxIters, nMinSecs ) 
  207.  
  208.       // Or should I have used DO CASE...ENDCASE for this? <g>
  209.  
  210.       IF nMax1 == nMax2 .AND. nMax1 == nMax3
  211.          lGoodTest := .T.
  212.          OutStd( CRLF )
  213.          OutStd( CRLF )
  214.       ELSE
  215.          nMaxIters := Int( Max( nMax1, Max( nMax2, nMax3 ) ) ;
  216.             * BUMP_UP_RATE * BUMP_UP_RATE )
  217.          OutStd( CRLF )
  218.          OutStd( CRLF )
  219.          OutStd( "The test just completed used a different" )
  220.          OutStd( CRLF )
  221.          OutStd( "number of iterations for the three phases." )
  222.          OutStd( CRLF )
  223.          OutStd( "The test is being repeated using a higher" )
  224.          OutStd( CRLF )
  225.          OutStd( "number of iterations." )
  226.          OutStd( CRLF )
  227.       ENDIF
  228.  
  229.    END
  230.  
  231.    OutStd( CRLF )
  232.    OutStd( CRLF )
  233.  
  234.    IF lGoodTest
  235.       OutStd( "-+-+-+ End of Test +-+-+-" )
  236.    ELSE
  237.       OutStd( "*** Test was interrupted ***" )
  238.    ENDIF
  239.  
  240.    OutStd( CRLF )
  241.  
  242.    RETURN ( NIL )
  243.  
  244. ///////////////////////////////////////////////////////////////////
  245.  
  246. /*
  247.    Phase1() compares the times required by CASE and IF structures
  248.    to locate the first .T. condition and then exit the structure.
  249. */
  250. STATIC FUNCTION Phase1( nMaxIters, nMinSecs )
  251.  
  252.    LOCAL nIters, cCond, nCond, nStart, nCase, nIf
  253.    LOCAL nExceedsBy
  254.    LOCAL lTooFast := .T.
  255.  
  256.    OutStd( CRLF )
  257.    OutStd( "Testing Phase  1 : Find .T. condition then exit structure" )
  258.    OutStd( CRLF )
  259.  
  260.    WHILE lTooFast
  261.  
  262.       BEGIN SEQUENCE
  263.  
  264.          OutStd( CRLF )
  265.          OutStd( "Number of iterations:", nMaxIters )
  266.          OutStd( CRLF )
  267.       
  268.          FOR nCond :=  1 TO COND_COUNT
  269.  
  270.             nStart := Seconds()
  271.  
  272.             FOR nIters :=  1 TO nMaxIters
  273.                DO CASE
  274.                CASE XCOND == C1
  275.                CASE XCOND == C2
  276.                CASE XCOND == C3
  277.                CASE XCOND == C4
  278.                CASE XCOND == C5
  279.                CASE XCOND == C6
  280.                CASE XCOND == C7
  281.                CASE XCOND == C8
  282.                CASE XCOND == C9
  283.                CASE XCOND == C10
  284.                CASE XCOND == C11
  285.                CASE XCOND == C12
  286.                CASE XCOND == C13
  287.                CASE XCOND == C14
  288.                CASE XCOND == C15
  289.                CASE XCOND == C16
  290.                CASE XCOND == C17
  291.                CASE XCOND == C18
  292.                CASE XCOND == C19
  293.                CASE XCOND == C20
  294.                CASE XCOND == C21
  295.                CASE XCOND == C22
  296.                CASE XCOND == C23
  297.                CASE XCOND == C24
  298.                OTHERWISE
  299.                ENDCASE
  300.             NEXT nIters
  301.  
  302.             nCase := Seconds() - nStart
  303.    
  304.             IF nCase < nMinSecs
  305.                nMaxIters := TooFast( nMaxIters )
  306.                BREAK
  307.             ENDIF 
  308.       
  309.             nStart := Seconds()
  310.  
  311.             FOR nIters :=  1 TO nMaxIters
  312.                IF     XCOND == C1
  313.                ELSEIF XCOND == C2
  314.                ELSEIF XCOND == C3
  315.                ELSEIF XCOND == C4
  316.                ELSEIF XCOND == C5
  317.                ELSEIF XCOND == C6
  318.                ELSEIF XCOND == C7
  319.                ELSEIF XCOND == C8
  320.                ELSEIF XCOND == C9
  321.                ELSEIF XCOND == C10
  322.                ELSEIF XCOND == C11
  323.                ELSEIF XCOND == C12
  324.                ELSEIF XCOND == C13
  325.                ELSEIF XCOND == C14
  326.                ELSEIF XCOND == C15
  327.                ELSEIF XCOND == C16
  328.                ELSEIF XCOND == C17
  329.                ELSEIF XCOND == C18
  330.                ELSEIF XCOND == C19
  331.                ELSEIF XCOND == C20
  332.                ELSEIF XCOND == C21
  333.                ELSEIF XCOND == C22
  334.                ELSEIF XCOND == C23
  335.                ELSEIF XCOND == C24
  336.                ELSE
  337.                ENDIF
  338.             NEXT nIters
  339.  
  340.             nIf := Seconds() - nStart
  341.    
  342.             IF nIf < nMinSecs
  343.                nMaxIters := TooFast( nMaxIters )
  344.                BREAK
  345.             ENDIF 
  346.  
  347.             ShowResult( nCond, nCase, nIf )
  348.  
  349.          NEXT nCond
  350.    
  351.          lTooFast := .F.
  352.    
  353.       END SEQUENCE
  354.    
  355.    END
  356.  
  357.    OutStd( CRLF )
  358.  
  359.    RETURN ( nMaxIters )
  360.  
  361. ///////////////////////////////////////////////////////////////////
  362.  
  363. /*
  364.    Phase2() compares the times required by CASE and IF structures
  365.    to move from testing one condition to testing the next one.
  366. */
  367. STATIC FUNCTION Phase2( nMaxIters, nMinSecs )
  368.  
  369.    LOCAL aPtToPt := Array( COND_COUNT, 2 )
  370.    LOCAL nStru, nCond, nIters, nLowSecs, nCase, nIf
  371.    LOCAL lTooFast := .T., nExceedsBy
  372.  
  373.    OutStd( CRLF )
  374.    OutStd( CRLF )
  375.    OutStd( "Testing Phase 2 : Stepping time between conditions" )
  376.    OutStd( CRLF )
  377.  
  378.    FOR nCond :=  1 TO COND_COUNT
  379.       aPtToPt[ nCond, 1 ] := 0
  380.       aPtToPt[ nCond, 2 ] := 0
  381.    NEXT nCond
  382.  
  383.    WHILE lTooFast
  384.  
  385.       BEGIN SEQUENCE
  386.  
  387.       OutStd( CRLF )
  388.       OutStd( "Number of iterations:", nMaxIters )
  389.       OutStd( CRLF )
  390.  
  391.       OutStd( CRLF )
  392.       OutStd( "Timing DO CASE...ENDCASE . . ." )
  393.       OutStd( CRLF )
  394.    
  395.       Elapsed( .T. )
  396.    
  397.       FOR nIters :=  1 TO nMaxIters
  398.    
  399.          nStru :=  1
  400.          nCond :=  1
  401.       
  402.          DO CASE
  403.          CASE ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++
  404.          CASE ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++
  405.          CASE ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++
  406.          CASE ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++
  407.          CASE ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++
  408.          CASE ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++
  409.          CASE ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++
  410.          CASE ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++
  411.          CASE ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++
  412.          CASE ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++
  413.          CASE ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++
  414.          CASE ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++
  415.          CASE ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++
  416.          CASE ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++
  417.          CASE ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++
  418.          CASE ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++
  419.          CASE ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++
  420.          CASE ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++
  421.          CASE ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++
  422.          CASE ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++
  423.          CASE ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++
  424.          CASE ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++
  425.          CASE ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++
  426.          CASE ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++
  427.          OTHERWISE
  428.             ( ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++ )
  429.          ENDCASE
  430.    
  431.       NEXT nIters
  432.  
  433.       OutStd( "(finished timing DO CASE...ENDCASE)" )
  434.       OutStd( CRLF )
  435.    
  436.       OutStd( CRLF )
  437.       OutStd( "Timing IF...ELSE...ENDIF . . ." )
  438.       OutStd( CRLF )
  439.    
  440.       Elapsed( .T. )
  441.    
  442.       FOR nIters :=  1 TO nMaxIters
  443.       
  444.          nStru := 2
  445.          nCond :=  1
  446.       
  447.          IF     ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++
  448.          ELSEIF ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++
  449.          ELSEIF ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++
  450.          ELSEIF ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++
  451.          ELSEIF ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++
  452.          ELSEIF ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++
  453.          ELSEIF ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++
  454.          ELSEIF ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++
  455.          ELSEIF ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++
  456.          ELSEIF ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++
  457.          ELSEIF ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++
  458.          ELSEIF ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++
  459.          ELSEIF ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++
  460.          ELSEIF ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++
  461.          ELSEIF ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++
  462.          ELSEIF ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++
  463.          ELSEIF ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++
  464.          ELSEIF ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++
  465.          ELSEIF ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++
  466.          ELSEIF ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++
  467.          ELSEIF ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++
  468.          ELSEIF ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++
  469.          ELSEIF ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++
  470.          ELSEIF ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++
  471.          ELSE
  472.             ( ( aPtToPt[ nCond, nStru ] += Elapsed(), -1 ) == nCond++ )
  473.          ENDIF
  474.    
  475.       NEXT nIters
  476.  
  477.       OutStd( CRLF )
  478.       OutStd( "(finished timing IF...ELSE...ENDIF)" )   
  479.       OutStd( CRLF )
  480.  
  481.       nCond :=  1
  482.    
  483.       OutStd( CRLF )
  484.       OutStd( "Results of Phase 2 'stepping' time comparisons:" )
  485.       OutStd( CRLF )
  486.  
  487.       nLowSecs := nMinSecs
  488.    
  489.       AEval( aPtToPt, { | a_ | ;
  490.             nCond++, ;
  491.             nCase := a_[  1 ], ;
  492.             nIf := a_[ 2 ], ;
  493.             nLowSecs := Min( nLowSecs, Min( nCase, nIf ) ), ;
  494.             ShowResult( nCond, nCase, nIf ) ;
  495.             } )
  496.       
  497.       IF nLowSecs < nMinSecs
  498.          nMaxIters := TooFast( nMaxIters )
  499.          BREAK
  500.       ENDIF
  501.    
  502.       lTooFast := .F.
  503.  
  504.       END SEQUENCE
  505.  
  506.    END
  507.  
  508.    OutStd( CRLF )
  509.          
  510.    RETURN ( nMaxIters )
  511.  
  512. ///////////////////////////////////////////////////////////////////
  513.  
  514. /*
  515.    Phase3() compares the times required by CASE and IF structures
  516.    to locate the first .T. condition and also the times required
  517.    to exit from the structure after locating the .T. condition.
  518. */
  519. STATIC FUNCTION Phase3( nMaxIters, nMinSecs )
  520.  
  521.    LOCAL nIters, cCond, nCond
  522.    LOCAL nStart, nCaseEntr, nCaseExit, nCase
  523.    LOCAL nIfEntr, nIfExit, nIf
  524.    LOCAL nExceedsBy
  525.    LOCAL lTooFast := .T.
  526.  
  527.    OutStd( CRLF )
  528.    OutStd( "Testing Phase 3 : 'seek' and 'exit' times" )
  529.    OutStd( CRLF )
  530.  
  531.    WHILE lTooFast
  532.  
  533.       BEGIN SEQUENCE
  534.  
  535.          OutStd( CRLF )
  536.          OutStd( "Number of iterations:", nMaxIters )
  537.          OutStd( CRLF )
  538.       
  539.          FOR nCond :=  1 TO COND_COUNT
  540.  
  541.             nCaseEntr := 0
  542.             nCaseExit := 0
  543.  
  544.             nStart := Seconds()
  545.  
  546.             FOR nIters :=  1 TO nMaxIters
  547.  
  548.                DO CASE
  549.                CASE XCOND == C1
  550.                   nCaseEntr += Seconds() - nStart
  551.                   nStart := Seconds()
  552.                CASE XCOND == C2
  553.                   nCaseEntr += Seconds() - nStart
  554.                   nStart := Seconds()
  555.                CASE XCOND == C3
  556.                   nCaseEntr += Seconds() - nStart
  557.                   nStart := Seconds()
  558.                CASE XCOND == C4
  559.                   nCaseEntr += Seconds() - nStart
  560.                   nStart := Seconds()
  561.                CASE XCOND == C5
  562.                   nCaseEntr += Seconds() - nStart
  563.                   nStart := Seconds()
  564.                CASE XCOND == C6
  565.                   nCaseEntr += Seconds() - nStart
  566.                   nStart := Seconds()
  567.                CASE XCOND == C7
  568.                   nCaseEntr += Seconds() - nStart
  569.                   nStart := Seconds()
  570.                CASE XCOND == C8
  571.                   nCaseEntr += Seconds() - nStart
  572.                   nStart := Seconds()
  573.                CASE XCOND == C9
  574.                   nCaseEntr += Seconds() - nStart
  575.                   nStart := Seconds()
  576.                CASE XCOND == C10
  577.                   nCaseEntr += Seconds() - nStart
  578.                   nStart := Seconds()
  579.                CASE XCOND == C11
  580.                   nCaseEntr += Seconds() - nStart
  581.                   nStart := Seconds()
  582.                CASE XCOND == C12
  583.                   nCaseEntr += Seconds() - nStart
  584.                   nStart := Seconds()
  585.                CASE XCOND == C13
  586.                   nCaseEntr += Seconds() - nStart
  587.                   nStart := Seconds()
  588.                CASE XCOND == C14
  589.                   nCaseEntr += Seconds() - nStart
  590.                   nStart := Seconds()
  591.                CASE XCOND == C15
  592.                   nCaseEntr += Seconds() - nStart
  593.                   nStart := Seconds()
  594.                CASE XCOND == C16
  595.                   nCaseEntr += Seconds() - nStart
  596.                   nStart := Seconds()
  597.                CASE XCOND == C17
  598.                   nCaseEntr += Seconds() - nStart
  599.                   nStart := Seconds()
  600.                CASE XCOND == C18
  601.                   nCaseEntr += Seconds() - nStart
  602.                   nStart := Seconds()
  603.                CASE XCOND == C19
  604.                   nCaseEntr += Seconds() - nStart
  605.                   nStart := Seconds()
  606.                CASE XCOND == C20
  607.                   nCaseEntr += Seconds() - nStart
  608.                   nStart := Seconds()
  609.                CASE XCOND == C21
  610.                   nCaseEntr += Seconds() - nStart
  611.                   nStart := Seconds()
  612.                CASE XCOND == C22
  613.                   nCaseEntr += Seconds() - nStart
  614.                   nStart := Seconds()
  615.                CASE XCOND == C23
  616.                   nCaseEntr += Seconds() - nStart
  617.                   nStart := Seconds()
  618.                CASE XCOND == C24
  619.                   nCaseEntr += Seconds() - nStart
  620.                   nStart := Seconds()
  621.                OTHERWISE
  622.                   nCaseEntr += Seconds() - nStart
  623.                   nStart := Seconds()
  624.                ENDCASE
  625.  
  626.                nCaseExit += Seconds() - nStart
  627.  
  628.             NEXT nIters
  629.  
  630.             nCase := nCaseExit + nCaseEntr
  631.    
  632.             IF nCase < nMinSecs
  633.                nMaxIters := TooFast( nMaxIters )
  634.                BREAK
  635.             ENDIF 
  636.  
  637.             nIfEntr := 0
  638.             nIfExit := 0
  639.       
  640.             nStart := Seconds()
  641.  
  642.             FOR nIters :=  1 TO nMaxIters
  643.  
  644.                IF     XCOND == C1
  645.                   nIfEntr += Seconds() - nStart
  646.                   nStart := Seconds()
  647.                ELSEIF XCOND == C2
  648.                   nIfEntr += Seconds() - nStart
  649.                   nStart := Seconds()
  650.                ELSEIF XCOND == C3
  651.                   nIfEntr += Seconds() - nStart
  652.                   nStart := Seconds()
  653.                ELSEIF XCOND == C4
  654.                   nIfEntr += Seconds() - nStart
  655.                   nStart := Seconds()
  656.                ELSEIF XCOND == C5
  657.                   nIfEntr += Seconds() - nStart
  658.                   nStart := Seconds()
  659.                ELSEIF XCOND == C6
  660.                   nIfEntr += Seconds() - nStart
  661.                   nStart := Seconds()
  662.                ELSEIF XCOND == C7
  663.                   nIfEntr += Seconds() - nStart
  664.                   nStart := Seconds()
  665.                ELSEIF XCOND == C8
  666.                   nIfEntr += Seconds() - nStart
  667.                   nStart := Seconds()
  668.                ELSEIF XCOND == C9
  669.                   nIfEntr += Seconds() - nStart
  670.                   nStart := Seconds()
  671.                ELSEIF XCOND == C10
  672.                   nIfEntr += Seconds() - nStart
  673.                   nStart := Seconds()
  674.                ELSEIF XCOND == C11
  675.                   nIfEntr += Seconds() - nStart
  676.                   nStart := Seconds()
  677.                ELSEIF XCOND == C12
  678.                   nIfEntr += Seconds() - nStart
  679.                   nStart := Seconds()
  680.                ELSEIF XCOND == C13
  681.                   nIfEntr += Seconds() - nStart
  682.                   nStart := Seconds()
  683.                ELSEIF XCOND == C14
  684.                   nIfEntr += Seconds() - nStart
  685.                   nStart := Seconds()
  686.                ELSEIF XCOND == C15
  687.                   nIfEntr += Seconds() - nStart
  688.                   nStart := Seconds()
  689.                ELSEIF XCOND == C16
  690.                   nIfEntr += Seconds() - nStart
  691.                   nStart := Seconds()
  692.                ELSEIF XCOND == C17
  693.                   nIfEntr += Seconds() - nStart
  694.                   nStart := Seconds()
  695.                ELSEIF XCOND == C18
  696.                   nIfEntr += Seconds() - nStart
  697.                   nStart := Seconds()
  698.                ELSEIF XCOND == C19
  699.                   nIfEntr += Seconds() - nStart
  700.                   nStart := Seconds()
  701.                ELSEIF XCOND == C20
  702.                   nIfEntr += Seconds() - nStart
  703.                   nStart := Seconds()
  704.                ELSEIF XCOND == C21
  705.                   nIfEntr += Seconds() - nStart
  706.                   nStart := Seconds()
  707.                ELSEIF XCOND == C22
  708.                   nIfEntr += Seconds() - nStart
  709.                   nStart := Seconds()
  710.                ELSEIF XCOND == C23
  711.                   nIfEntr += Seconds() - nStart
  712.                   nStart := Seconds()
  713.                ELSEIF XCOND == C24
  714.                   nIfEntr += Seconds() - nStart
  715.                   nStart := Seconds()
  716.                ELSE
  717.                   nIfEntr += Seconds() - nStart
  718.                   nStart := Seconds()
  719.                ENDIF
  720.  
  721.                nIfExit += Seconds() - nStart
  722.  
  723.             NEXT nIters
  724.  
  725.             nIf := nIfExit + nIfEntr
  726.  
  727.             OutStd( CRLF )
  728.  
  729.             ShowResult( nCond, nCaseEntr, nIfEntr, "(Seek)" )
  730.             ShowResult( nCond, nCaseExit, nIfExit, "(Exit)" )
  731.             ShowResult( nCond, nCase, nIf, "(Total)" )
  732.  
  733.          NEXT nCond
  734.    
  735.          lTooFast := .F.
  736.    
  737.       END SEQUENCE
  738.    
  739.    END
  740.  
  741.    OutStd( CRLF )
  742.  
  743.    RETURN ( nMaxIters )
  744.  
  745. ///////////////////////////////////////////////////////////////////
  746.    
  747. /*
  748.    TooFast() is called by Phase1(), Phase2(), and Phase3().
  749. */
  750. STATIC FUNCTION TooFast( nMaxIters )
  751.  
  752.    OutStd( CRLF )
  753.    OutStd( CRLF )
  754.    OutStd( LTrim( Str( nMaxIters, 6, 0 ) ), ;
  755.       "iterations are too fast", ;
  756.       "to provide the minimum seconds count;" )
  757.    OutStd( CRLF )
  758.    OutStd( "bumping up to", ;
  759.       Str( nMaxIters := Int( nMaxIters * BUMP_UP_RATE ), 6, 0 ) )
  760.    OutStd( CRLF )
  761.  
  762.    RETURN ( Int( nMaxIters ) )
  763.  
  764. ///////////////////////////////////////////////////////////////////
  765.  
  766. /*
  767.    Elapsed() returns the time, in seconds, that has passed since
  768.    the prior call to Elapsed.  It is called from Phase2().
  769. */
  770. STATIC FUNCTION Elapsed( lReset )
  771.  
  772.    STATIC nLastSecs := 0
  773.  
  774.    LOCAL nElapsed
  775.  
  776.    IF VALTYPE( lReset ) == "L" .AND. lReset == .T.
  777.       nLastSecs := Seconds()
  778.    ENDIF
  779.  
  780.    nElapsed := Seconds() - nLastSecs
  781.  
  782.    nLastSecs := Seconds()
  783.  
  784.    RETURN ( nElapsed )
  785.  
  786. ///////////////////////////////////////////////////////////////////
  787.  
  788. /*
  789.    ShowResult() is called from Phase1(), Phase2(), and Phase3().
  790. */
  791. STATIC FUNCTION ShowResult( nCond, nCase, nIf, cLabel )
  792.  
  793.    LOCAL nExceedsBy
  794.  
  795.    IF cLabel == NIL
  796.       cLabel := "Cond. #"
  797.    ENDIF
  798.  
  799.    cLabel := Left( RTrim( cLabel) + ":" + Space( 7 ), 7 )
  800.  
  801.    IF Min( nCase, nIf ) <= 0
  802.       nExceedsBy := 0
  803.    ELSE
  804.       nExceedsBy := ( ( Max( nCase, nIf ) ;
  805.          / Min( nCase, nIf ) ) -  1 ) *  100
  806.    ENDIF
  807.     
  808.    OutStd( CRLF )
  809.    OutStd( cLabel, Str( nCond, 3, 0 ) )
  810.    OutStd( "; CASE:", Str( nCase, 6, 2 ), "sec." )
  811.    OutStd( "; IF:", Str( nIf, 6, 2 ), "sec." )
  812.    OutStd( If( nCase < nIf, " -  CASE", ;
  813.          If( nIf < nCase, " -  IF  ", " -  (even)" ) ) )
  814.    IF nExceedsBy > 0
  815.       OutStd( " by", Str( nExceedsBy, 6, 2 ) + "%" )
  816.    ENDIF
  817.  
  818. RETURN ( NIL )
  819.  
  820. ///////////////////////  END OF MODULE ////////////////////////////
  821.  
  822. // This output is from running the program without debug.
  823.  
  824. CaseVsIf: A Utility for Comparing execution times
  825. of the multi-branch decision structures:
  826.  
  827. DO CASE...ENDCASE versus IF...ELSE...ENDIF
  828.  
  829. For phases 1 and 3, conditions are character comparisons, such as:
  830.  
  831.     Chr( nCond ) == ;
  832.     Chr(  1 )
  833.  
  834. Starting nMaxIters value: 25000
  835. Minimum number of seconds for all results:  5.00
  836.  
  837. Testing Phase  1 : Find .T. condition then exit structure
  838.  
  839. Number of iterations: 25000
  840.  
  841. Cond. #   1; CASE:   6.86 sec.; IF:  14.50 sec. -  CASE by 111.37%
  842. Cond. #   2; CASE:  10.71 sec.; IF:  18.29 sec. -  CASE by  70.77%
  843. Cond. #   3; CASE:  14.66 sec.; IF:  21.97 sec. -  CASE by  49.86%
  844. Cond. #   4; CASE:  18.56 sec.; IF:  25.76 sec. -  CASE by  38.79%
  845. Cond. #   5; CASE:  22.47 sec.; IF:  29.49 sec. -  CASE by  31.24%
  846. Cond. #   6; CASE:  26.42 sec.; IF:  33.23 sec. -  CASE by  25.78%
  847. Cond. #   7; CASE:  30.27 sec.; IF:  36.96 sec. -  CASE by  22.10%
  848. Cond. #   8; CASE:  34.16 sec.; IF:  40.70 sec. -  CASE by  19.15%
  849. Cond. #   9; CASE:  38.06 sec.; IF:  44.49 sec. -  CASE by  16.89%
  850. Cond. #  10; CASE:  42.02 sec.; IF:  48.22 sec. -  CASE by  14.75%
  851. Cond. #  11; CASE:  45.86 sec.; IF:  51.96 sec. -  CASE by  13.30%
  852. Cond. #  12; CASE:  49.76 sec.; IF:  55.70 sec. -  CASE by  11.94%
  853. Cond. #  13; CASE:  53.71 sec.; IF:  59.54 sec. -  CASE by  10.85%
  854. Cond. #  14; CASE:  57.67 sec.; IF:  63.39 sec. -  CASE by   9.92%
  855. Cond. #  15; CASE:  61.51 sec.; IF:  67.12 sec. -  CASE by   9.12%
  856. Cond. #  16; CASE:  65.41 sec.; IF:  70.91 sec. -  CASE by   8.41%
  857. Cond. #  17; CASE:  69.37 sec.; IF:  74.65 sec. -  CASE by   7.61%
  858. Cond. #  18; CASE:  73.32 sec.; IF:  78.38 sec. -  CASE by   6.90%
  859. Cond. #  19; CASE:  77.17 sec.; IF:  82.17 sec. -  CASE by   6.48%
  860. Cond. #  20; CASE:  81.07 sec.; IF:  85.95 sec. -  CASE by   6.02%
  861. Cond. #  21; CASE:  85.03 sec.; IF:  89.64 sec. -  CASE by   5.42%
  862. Cond. #  22; CASE:  88.93 sec.; IF:  93.42 sec. -  CASE by   5.05%
  863. Cond. #  23; CASE:  92.83 sec.; IF:  97.22 sec. -  CASE by   4.73%
  864. Cond. #  24; CASE:  96.78 sec.; IF: 100.95 sec. -  CASE by   4.31%
  865. Cond. #  25; CASE:  96.78 sec.; IF: 100.84 sec. -  CASE by   4.20%
  866.  
  867.  
  868. Testing Phase 2 : Stepping time between conditions
  869.  
  870. Number of iterations: 25000
  871.  
  872. Timing DO CASE...ENDCASE . . .
  873. (finished timing DO CASE...ENDCASE)
  874.  
  875. Timing IF...ELSE...ENDIF . . .
  876.  
  877. (finished timing IF...ELSE...ENDIF)
  878.  
  879. Results of Phase 2 'stepping' time comparisons:
  880.  
  881. Cond. #   2; CASE:  46.58 sec.; IF:  46.25 sec. -  IF   by   0.71%
  882. Cond. #   3; CASE:  36.31 sec.; IF:  36.66 sec. -  CASE by   0.96%
  883. Cond. #   4; CASE:  37.10 sec.; IF:  37.93 sec. -  CASE by   2.24%
  884. Cond. #   5; CASE:  37.09 sec.; IF:  41.15 sec. -  CASE by  10.95%
  885. Cond. #   6; CASE:  37.95 sec.; IF:  38.05 sec. -  CASE by   0.26%
  886. Cond. #   7; CASE:  38.52 sec.; IF:  37.89 sec. -  IF   by   1.66%
  887. Cond. #   8; CASE:  38.11 sec.; IF:  37.95 sec. -  IF   by   0.42%
  888. Cond. #   9; CASE:  38.97 sec.; IF:  37.97 sec. -  IF   by   2.63%
  889. Cond. #  10; CASE:  38.61 sec.; IF:  38.73 sec. -  CASE by   0.31%
  890. Cond. #  11; CASE:  38.96 sec.; IF:  38.57 sec. -  IF   by   1.01%
  891. Cond. #  12; CASE:  38.13 sec.; IF:  39.63 sec. -  CASE by   3.93%
  892. Cond. #  13; CASE:  41.20 sec.; IF:  39.49 sec. -  IF   by   4.33%
  893. Cond. #  14; CASE:  35.45 sec.; IF:  40.62 sec. -  CASE by  14.58%
  894. Cond. #  15; CASE:  36.82 sec.; IF:  40.20 sec. -  CASE by   9.18%
  895. Cond. #  16; CASE:  38.26 sec.; IF:  40.45 sec. -  CASE by   5.72%
  896. Cond. #  17; CASE:  38.72 sec.; IF:  40.69 sec. -  CASE by   5.09%
  897. Cond. #  18; CASE:  38.52 sec.; IF:  40.94 sec. -  CASE by   6.28%
  898. Cond. #  19; CASE:  38.64 sec.; IF:  40.92 sec. -  CASE by   5.90%
  899. Cond. #  20; CASE:  37.55 sec.; IF:  40.64 sec. -  CASE by   8.23%
  900. Cond. #  21; CASE:  37.41 sec.; IF:  40.62 sec. -  CASE by   8.58%
  901. Cond. #  22; CASE:  38.98 sec.; IF:  40.40 sec. -  CASE by   3.64%
  902. Cond. #  23; CASE:  38.38 sec.; IF:  40.78 sec. -  CASE by   6.25%
  903. Cond. #  24; CASE:  39.11 sec.; IF:  39.93 sec. -  CASE by   2.10%
  904. Cond. #  25; CASE:  37.86 sec.; IF:  40.82 sec. -  CASE by   7.82%
  905. Cond. #  26; CASE:  38.30 sec.; IF:  40.07 sec. -  CASE by   4.62%
  906.  
  907. Testing Phase 3 : 'seek' and 'exit' times
  908.  
  909. Number of iterations: 25000
  910.  
  911.  
  912. (Seek):   1; CASE:  45.87 sec.; IF:  45.81 sec. -  IF   by   0.13%
  913. (Exit):   1; CASE:  17.66 sec.; IF:  17.46 sec. -  IF   by   1.15%
  914. (Total)   1; CASE:  63.53 sec.; IF:  63.27 sec. -  IF   by   0.41%
  915.  
  916. (Seek):   2; CASE:  48.43 sec.; IF:  48.30 sec. -  IF   by   0.27%
  917. (Exit):   2; CASE:  16.51 sec.; IF:  15.26 sec. -  IF   by   8.19%
  918. (Total)   2; CASE:  64.94 sec.; IF:  63.56 sec. -  IF   by   2.17%
  919.  
  920. (Seek):   3; CASE:  52.75 sec.; IF:  51.70 sec. -  IF   by   2.03%
  921. (Exit):   3; CASE:  16.63 sec.; IF:  15.96 sec. -  IF   by   4.20%
  922. (Total)   3; CASE:  69.38 sec.; IF:  67.66 sec. -  IF   by   2.54%
  923.  
  924. (Seek):   4; CASE:  57.60 sec.; IF:  56.53 sec. -  IF   by   1.89%
  925. (Exit):   4; CASE:  17.08 sec.; IF:  17.43 sec. -  CASE by   2.05%
  926. (Total)   4; CASE:  74.68 sec.; IF:  73.96 sec. -  IF   by   0.97%
  927.  
  928. (Seek):   5; CASE:  60.25 sec.; IF:  56.91 sec. -  IF   by   5.87%
  929. (Exit):   5; CASE:  17.11 sec.; IF:  16.25 sec. -  IF   by   5.29%
  930. (Total)   5; CASE:  77.36 sec.; IF:  73.16 sec. -  IF   by   5.74%
  931.  
  932. (Seek):   6; CASE:  63.42 sec.; IF:  65.41 sec. -  CASE by   3.14%
  933. (Exit):   6; CASE:  16.84 sec.; IF:  19.02 sec. -  CASE by  12.95%
  934. (Total)   6; CASE:  80.26 sec.; IF:  84.43 sec. -  CASE by   5.20%
  935.  
  936. (Seek):   7; CASE:  70.19 sec.; IF:  67.72 sec. -  IF   by   3.65%
  937. (Exit):   7; CASE:  18.41 sec.; IF:  17.59 sec. -  IF   by   4.66%
  938. (Total)   7; CASE:  88.60 sec.; IF:  85.31 sec. -  IF   by   3.86%
  939.  
  940. (Seek):   8; CASE:  68.28 sec.; IF:  72.53 sec. -  CASE by   6.22%
  941. (Exit):   8; CASE:  14.65 sec.; IF:  18.16 sec. -  CASE by  23.96%
  942. (Total)   8; CASE:  82.93 sec.; IF:  90.69 sec. -  CASE by   9.36%
  943.  
  944. (Seek):   9; CASE:  77.15 sec.; IF:  75.19 sec. -  IF   by   2.61%
  945. (Exit):   9; CASE:  17.32 sec.; IF:  17.97 sec. -  CASE by   3.75%
  946. (Total)   9; CASE:  94.47 sec.; IF:  93.16 sec. -  IF   by   1.41%
  947.  
  948. (Seek):  10; CASE:  81.25 sec.; IF:  79.11 sec. -  IF   by   2.71%
  949. (Exit):  10; CASE:  17.17 sec.; IF:  17.90 sec. -  CASE by   4.25%
  950. (Total)  10; CASE:  98.42 sec.; IF:  97.01 sec. -  IF   by   1.45%
  951.  
  952. (Seek):  11; CASE:  84.41 sec.; IF:  82.40 sec. -  IF   by   2.44%
  953. (Exit):  11; CASE:  16.54 sec.; IF:  16.48 sec. -  IF   by   0.36%
  954. (Total)  11; CASE: 100.95 sec.; IF:  98.88 sec. -  IF   by   2.09%
  955.  
  956. (Seek):  12; CASE:  88.10 sec.; IF:  84.66 sec. -  IF   by   4.06%
  957. (Exit):  12; CASE:  17.36 sec.; IF:  15.77 sec. -  IF   by  10.08%
  958. (Total)  12; CASE: 105.46 sec.; IF: 100.43 sec. -  IF   by   5.01%
  959.  
  960. (Seek):  13; CASE:  92.41 sec.; IF:  89.50 sec. -  IF   by   3.25%
  961. (Exit):  13; CASE:  17.98 sec.; IF:  15.94 sec. -  IF   by  12.80%
  962. (Total)  13; CASE: 110.39 sec.; IF: 105.44 sec. -  IF   by   4.69%
  963.  
  964. (Seek):  14; CASE:  96.25 sec.; IF:  93.82 sec. -  IF   by   2.59%
  965. (Exit):  14; CASE:  15.83 sec.; IF:  17.31 sec. -  CASE by   9.35%
  966. (Total)  14; CASE: 112.08 sec.; IF: 111.13 sec. -  IF   by   0.85%
  967.  
  968. (Seek):  15; CASE: 101.35 sec.; IF:  99.07 sec. -  IF   by   2.30%
  969. (Exit):  15; CASE:  18.12 sec.; IF:  20.62 sec. -  CASE by  13.80%
  970. (Total)  15; CASE: 119.47 sec.; IF: 119.69 sec. -  CASE by   0.18%
  971.  
  972. (Seek):  16; CASE: 106.38 sec.; IF: 101.68 sec. -  IF   by   4.62%
  973. (Exit):  16; CASE:  21.48 sec.; IF:  17.76 sec. -  IF   by  20.95%
  974. (Total)  16; CASE: 127.86 sec.; IF: 119.44 sec. -  IF   by   7.05%
  975.  
  976. (Seek):  17; CASE: 110.54 sec.; IF: 105.41 sec. -  IF   by   4.87%
  977. (Exit):  17; CASE:  19.83 sec.; IF:  16.64 sec. -  IF   by  19.17%
  978. (Total)  17; CASE: 130.37 sec.; IF: 122.05 sec. -  IF   by   6.82%
  979.  
  980. (Seek):  18; CASE: 112.26 sec.; IF: 108.12 sec. -  IF   by   3.83%
  981. (Exit):  18; CASE:  13.42 sec.; IF:  12.02 sec. -  IF   by  11.65%
  982. (Total)  18; CASE: 125.68 sec.; IF: 120.14 sec. -  IF   by   4.61%
  983.  
  984. (Seek):  19; CASE: 116.64 sec.; IF: 113.25 sec. -  IF   by   2.99%
  985. (Exit):  19; CASE:  13.40 sec.; IF:  13.46 sec. -  CASE by   0.45%
  986. (Total)  19; CASE: 130.04 sec.; IF: 126.71 sec. -  IF   by   2.63%
  987.  
  988. (Seek):  20; CASE: 119.97 sec.; IF: 116.14 sec. -  IF   by   3.30%
  989. (Exit):  20; CASE:  12.94 sec.; IF:  14.73 sec. -  CASE by  13.83%
  990. (Total)  20; CASE: 132.91 sec.; IF: 130.87 sec. -  IF   by   1.56%
  991.  
  992. (Seek):  21; CASE: 121.86 sec.; IF: 122.45 sec. -  CASE by   0.48%
  993. (Exit):  21; CASE:  12.84 sec.; IF:  11.99 sec. -  IF   by   7.09%
  994. (Total)  21; CASE: 134.70 sec.; IF: 134.44 sec. -  IF   by   0.19%
  995.  
  996. (Seek):  22; CASE: 127.79 sec.; IF: 122.70 sec. -  IF   by   4.15%
  997. (Exit):  22; CASE:  12.33 sec.; IF:  12.15 sec. -  IF   by   1.48%
  998. (Total)  22; CASE: 140.12 sec.; IF: 134.85 sec. -  IF   by   3.91%
  999.  
  1000. (Seek):  23; CASE: 132.53 sec.; IF: 127.02 sec. -  IF   by   4.34%
  1001. (Exit):  23; CASE:  14.64 sec.; IF:  12.27 sec. -  IF   by  19.32%
  1002. (Total)  23; CASE: 147.17 sec.; IF: 139.29 sec. -  IF   by   5.66%
  1003.  
  1004. (Seek):  24; CASE: 136.39 sec.; IF: 130.90 sec. -  IF   by   4.19%
  1005. (Exit):  24; CASE:  12.51 sec.; IF:  12.12 sec. -  IF   by   3.22%
  1006. (Total)  24; CASE: 148.90 sec.; IF: 143.02 sec. -  IF   by   4.11%
  1007.  
  1008. (Seek):  25; CASE: 136.29 sec.; IF: 130.67 sec. -  IF   by   4.30%
  1009. (Exit):  25; CASE:  13.18 sec.; IF:  11.66 sec. -  IF   by  13.04%
  1010. (Total)  25; CASE: 149.47 sec.; IF: 142.33 sec. -  IF   by   5.02%
  1011.  
  1012. -+-+-+ End of Test +-+-+-
  1013.  
  1014. // This output is from running the program _with_ debug.
  1015.  
  1016. CaseVsIf: A Utility for Comparing execution times
  1017. of the multi-branch decision structures:
  1018.  
  1019. DO CASE...ENDCASE versus IF...ELSE...ENDIF
  1020.  
  1021. For phases 1 and 3, conditions are character comparisons, such as:
  1022.  
  1023.     Chr( nCond ) == ;
  1024.     Chr(  1 )
  1025.  
  1026. Starting nMaxIters value: 25000
  1027. Minimum number of seconds for all results:  5.00
  1028.  
  1029. Testing Phase  1 : Find .T. condition then exit structure
  1030.  
  1031. Number of iterations: 25000
  1032.  
  1033. Cond. #   1; CASE:  19.11 sec.; IF:  20.93 sec. -  CASE by   9.52%
  1034. Cond. #   2; CASE:  29.11 sec.; IF:  24.83 sec. -  IF   by  17.24%
  1035. Cond. #   3; CASE:  39.11 sec.; IF:  28.72 sec. -  IF   by  36.18%
  1036. Cond. #   4; CASE:  49.22 sec.; IF:  32.62 sec. -  IF   by  50.89%
  1037. Cond. #   5; CASE:  59.27 sec.; IF:  36.47 sec. -  IF   by  62.52%
  1038. Cond. #   6; CASE:  69.32 sec.; IF:  40.42 sec. -  IF   by  71.50%
  1039. Cond. #   7; CASE:  79.37 sec.; IF:  44.27 sec. -  IF   by  79.29%
  1040. Cond. #   8; CASE:  89.42 sec.; IF:  48.23 sec. -  IF   by  85.40%
  1041. Cond. #   9; CASE:  99.41 sec.; IF:  52.12 sec. -  IF   by  90.73%
  1042. Cond. #  10; CASE: 109.47 sec.; IF:  56.02 sec. -  IF   by  95.41%
  1043. Cond. #  11; CASE: 119.52 sec.; IF:  59.87 sec. -  IF   by  99.63%
  1044. Cond. #  12; CASE: 129.57 sec.; IF:  63.82 sec. -  IF   by 103.02%
  1045. Cond. #  13; CASE: 139.62 sec.; IF:  67.83 sec. -  IF   by 105.84%
  1046. Cond. #  14; CASE: 149.61 sec.; IF:  71.85 sec. -  IF   by 108.23%
  1047. Cond. #  15; CASE: 159.72 sec.; IF:  75.69 sec. -  IF   by 111.02%
  1048. Cond. #  16; CASE: 169.72 sec.; IF:  79.59 sec. -  IF   by 113.24%
  1049. Cond. #  17; CASE: 179.83 sec.; IF:  83.48 sec. -  IF   by 115.42%
  1050. Cond. #  18; CASE: 189.82 sec.; IF:  87.45 sec. -  IF   by 117.06%
  1051. Cond. #  19; CASE: 199.93 sec.; IF:  91.28 sec. -  IF   by 119.03%
  1052. Cond. #  20; CASE: 209.93 sec.; IF:  95.18 sec. -  IF   by 120.56%
  1053. Cond. #  21; CASE: 219.97 sec.; IF:  99.09 sec. -  IF   by 121.99%
  1054. Cond. #  22; CASE: 230.03 sec.; IF: 103.04 sec. -  IF   by 123.24%
  1055. Cond. #  23; CASE: 240.08 sec.; IF: 106.88 sec. -  IF   by 124.63%
  1056. Cond. #  24; CASE: 250.07 sec.; IF: 110.79 sec. -  IF   by 125.72%
  1057. Cond. #  25; CASE: 256.01 sec.; IF: 110.67 sec. -  IF   by 131.33%
  1058.  
  1059.  
  1060. Testing Phase 2 : Stepping time between conditions
  1061.  
  1062. Number of iterations: 25000
  1063.  
  1064. Timing DO CASE...ENDCASE . . .
  1065. (finished timing DO CASE...ENDCASE)
  1066.  
  1067. Timing IF...ELSE...ENDIF . . .
  1068.  
  1069. (finished timing IF...ELSE...ENDIF)
  1070.  
  1071. Results of Phase 2 'stepping' time comparisons:
  1072.  
  1073. Cond. #   2; CASE: 101.88 sec.; IF:  95.82 sec. -  IF   by   6.32%
  1074. Cond. #   3; CASE:  76.15 sec.; IF:  72.22 sec. -  IF   by   5.44%
  1075. Cond. #   4; CASE:  74.99 sec.; IF:  68.93 sec. -  IF   by   8.79%
  1076. Cond. #   5; CASE:  76.02 sec.; IF:  76.00 sec. -  IF   by   0.03%
  1077. Cond. #   6; CASE:  76.19 sec.; IF:  69.40 sec. -  IF   by   9.78%
  1078. Cond. #   7; CASE:  77.80 sec.; IF:  71.71 sec. -  IF   by   8.49%
  1079. Cond. #   8; CASE:  77.42 sec.; IF:  70.43 sec. -  IF   by   9.92%
  1080. Cond. #   9; CASE:  76.32 sec.; IF:  69.37 sec. -  IF   by  10.02%
  1081. Cond. #  10; CASE:  74.97 sec.; IF:  70.61 sec. -  IF   by   6.17%
  1082. Cond. #  11; CASE:  76.14 sec.; IF:  68.47 sec. -  IF   by  11.20%
  1083. Cond. #  12; CASE:  76.16 sec.; IF:  71.60 sec. -  IF   by   6.37%
  1084. Cond. #  13; CASE:  80.62 sec.; IF:  69.44 sec. -  IF   by  16.10%
  1085. Cond. #  14; CASE:  75.98 sec.; IF:  72.75 sec. -  IF   by   4.44%
  1086. Cond. #  15; CASE:  76.05 sec.; IF:  69.42 sec. -  IF   by   9.55%
  1087. Cond. #  16; CASE:  77.05 sec.; IF:  70.95 sec. -  IF   by   8.60%
  1088. Cond. #  17; CASE:  75.15 sec.; IF:  69.29 sec. -  IF   by   8.46%
  1089. Cond. #  18; CASE:  76.15 sec.; IF:  72.08 sec. -  IF   by   5.65%
  1090. Cond. #  19; CASE:  74.70 sec.; IF:  68.90 sec. -  IF   by   8.42%
  1091. Cond. #  20; CASE:  77.20 sec.; IF:  70.53 sec. -  IF   by   9.46%
  1092. Cond. #  21; CASE:  76.97 sec.; IF:  69.83 sec. -  IF   by  10.22%
  1093. Cond. #  22; CASE:  76.70 sec.; IF:  70.44 sec. -  IF   by   8.89%
  1094. Cond. #  23; CASE:  76.52 sec.; IF:  70.45 sec. -  IF   by   8.62%
  1095. Cond. #  24; CASE:  73.90 sec.; IF:  69.53 sec. -  IF   by   6.29%
  1096. Cond. #  25; CASE:  76.51 sec.; IF:  69.27 sec. -  IF   by  10.45%
  1097. Cond. #  26; CASE:  82.49 sec.; IF:  75.11 sec. -  IF   by   9.83%
  1098.  
  1099. Testing Phase 3 : 'seek' and 'exit' times
  1100.  
  1101. Number of iterations: 25000
  1102.  
  1103.  
  1104. (Seek):   1; CASE:  71.07 sec.; IF:  63.98 sec. -  IF   by  11.08%
  1105. (Exit):   1; CASE:  24.12 sec.; IF:  22.90 sec. -  IF   by   5.33%
  1106. (Total)   1; CASE:  95.19 sec.; IF:  86.88 sec. -  IF   by   9.56%
  1107.  
  1108. (Seek):   2; CASE:  80.22 sec.; IF:  71.22 sec. -  IF   by  12.64%
  1109. (Exit):   2; CASE:  24.86 sec.; IF:  27.77 sec. -  CASE by  11.71%
  1110. (Total)   2; CASE: 105.08 sec.; IF:  98.99 sec. -  IF   by   6.15%
  1111.  
  1112. (Seek):   3; CASE:  93.15 sec.; IF:  71.45 sec. -  IF   by  30.37%
  1113. (Exit):   3; CASE:  24.70 sec.; IF:  23.03 sec. -  IF   by   7.25%
  1114. (Total)   3; CASE: 117.85 sec.; IF:  94.48 sec. -  IF   by  24.74%
  1115.  
  1116. (Seek):   4; CASE: 102.75 sec.; IF:  74.72 sec. -  IF   by  37.51%
  1117. (Exit):   4; CASE:  24.84 sec.; IF:  22.67 sec. -  IF   by   9.57%
  1118. (Total)   4; CASE: 127.59 sec.; IF:  97.39 sec. -  IF   by  31.01%
  1119.  
  1120. (Seek):   5; CASE: 111.95 sec.; IF:  79.51 sec. -  IF   by  40.80%
  1121. (Exit):   5; CASE:  22.55 sec.; IF:  23.11 sec. -  CASE by   2.48%
  1122. (Total)   5; CASE: 134.50 sec.; IF: 102.62 sec. -  IF   by  31.07%
  1123.  
  1124. (Seek):   6; CASE: 121.55 sec.; IF:  84.20 sec. -  IF   by  44.36%
  1125. (Exit):   6; CASE:  25.00 sec.; IF:  22.77 sec. -  IF   by   9.79%
  1126. (Total)   6; CASE: 146.55 sec.; IF: 106.97 sec. -  IF   by  37.00%
  1127.  
  1128. (Seek):   7; CASE: 130.04 sec.; IF:  84.60 sec. -  IF   by  53.71%
  1129. (Exit):   7; CASE:  24.47 sec.; IF:  21.42 sec. -  IF   by  14.24%
  1130. (Total)   7; CASE: 154.51 sec.; IF: 106.02 sec. -  IF   by  45.74%
  1131.  
  1132. (Seek):   8; CASE: 141.00 sec.; IF:  93.28 sec. -  IF   by  51.16%
  1133. (Exit):   8; CASE:  24.83 sec.; IF:  24.96 sec. -  CASE by   0.52%
  1134. (Total)   8; CASE: 165.83 sec.; IF: 118.24 sec. -  IF   by  40.25%
  1135.  
  1136. (Seek):   9; CASE: 151.02 sec.; IF:  98.68 sec. -  IF   by  53.04%
  1137. (Exit):   9; CASE:  23.97 sec.; IF:  26.12 sec. -  CASE by   8.97%
  1138. (Total)   9; CASE: 174.99 sec.; IF: 124.80 sec. -  IF   by  40.22%
  1139.  
  1140. (Seek):  10; CASE: 159.53 sec.; IF:  98.05 sec. -  IF   by  62.70%
  1141. (Exit):  10; CASE:  22.60 sec.; IF:  22.25 sec. -  IF   by   1.57%
  1142. (Total)  10; CASE: 182.13 sec.; IF: 120.30 sec. -  IF   by  51.40%
  1143.  
  1144. (Seek):  11; CASE: 173.09 sec.; IF:  98.10 sec. -  IF   by  76.44%
  1145. (Exit):  11; CASE:  24.69 sec.; IF:  20.68 sec. -  IF   by  19.39%
  1146. (Total)  11; CASE: 197.78 sec.; IF: 118.78 sec. -  IF   by  66.51%
  1147.  
  1148. (Seek):  12; CASE: 180.07 sec.; IF: 104.22 sec. -  IF   by  72.78%
  1149. (Exit):  12; CASE:  22.18 sec.; IF:  21.50 sec. -  IF   by   3.16%
  1150. (Total)  12; CASE: 202.25 sec.; IF: 125.72 sec. -  IF   by  60.87%
  1151.  
  1152. (Seek):  13; CASE: 191.61 sec.; IF: 112.11 sec. -  IF   by  70.91%
  1153. (Exit):  13; CASE:  23.26 sec.; IF:  24.52 sec. -  CASE by   5.42%
  1154. (Total)  13; CASE: 214.87 sec.; IF: 136.63 sec. -  IF   by  57.26%
  1155.  
  1156. (Seek):  14; CASE: 200.83 sec.; IF: 115.85 sec. -  IF   by  73.35%
  1157. (Exit):  14; CASE:  22.54 sec.; IF:  25.18 sec. -  CASE by  11.71%
  1158. (Total)  14; CASE: 223.37 sec.; IF: 141.03 sec. -  IF   by  58.38%
  1159.  
  1160. (Seek):  15; CASE: 210.88 sec.; IF: 116.20 sec. -  IF   by  81.48%
  1161. (Exit):  15; CASE:  24.84 sec.; IF:  22.17 sec. -  IF   by  12.04%
  1162. (Total)  15; CASE: 235.72 sec.; IF: 138.37 sec. -  IF   by  70.35%
  1163.  
  1164. (Seek):  16; CASE: 221.39 sec.; IF: 122.54 sec. -  IF   by  80.67%
  1165. (Exit):  16; CASE:  24.76 sec.; IF:  23.58 sec. -  IF   by   5.00%
  1166. (Total)  16; CASE: 246.15 sec.; IF: 146.12 sec. -  IF   by  68.46%
  1167.  
  1168. (Seek):  17; CASE: 231.90 sec.; IF: 126.54 sec. -  IF   by  83.26%
  1169. (Exit):  17; CASE:  23.53 sec.; IF:  24.09 sec. -  CASE by   2.38%
  1170. (Total)  17; CASE: 255.43 sec.; IF: 150.63 sec. -  IF   by  69.57%
  1171.  
  1172. (Seek):  18; CASE: 240.28 sec.; IF: 130.14 sec. -  IF   by  84.63%
  1173. (Exit):  18; CASE:  18.79 sec.; IF:  19.41 sec. -  CASE by   3.30%
  1174. (Total)  18; CASE: 259.07 sec.; IF: 149.55 sec. -  IF   by  73.23%
  1175.  
  1176. (Seek):  19; CASE: 254.25 sec.; IF: 133.24 sec. -  IF   by  90.82%
  1177. (Exit):  19; CASE:  20.11 sec.; IF:  20.77 sec. -  CASE by   3.28%
  1178. (Total)  19; CASE: 274.36 sec.; IF: 154.01 sec. -  IF   by  78.14%
  1179.  
  1180. (Seek):  20; CASE: 261.81 sec.; IF: 135.74 sec. -  IF   by  92.88%
  1181. (Exit):  20; CASE:  20.06 sec.; IF:  18.75 sec. -  IF   by   6.99%
  1182. (Total)  20; CASE: 281.87 sec.; IF: 154.49 sec. -  IF   by  82.45%
  1183.  
  1184. (Seek):  21; CASE: 272.18 sec.; IF: 141.29 sec. -  IF   by  92.64%
  1185. (Exit):  21; CASE:  20.66 sec.; IF:  20.13 sec. -  IF   by   2.63%
  1186. (Total)  21; CASE: 292.84 sec.; IF: 161.42 sec. -  IF   by  81.41%
  1187.  
  1188. (Seek):  22; CASE: 282.66 sec.; IF: 145.96 sec. -  IF   by  93.66%
  1189. (Exit):  22; CASE:  20.35 sec.; IF:  20.33 sec. -  IF   by   0.10%
  1190. (Total)  22; CASE: 303.01 sec.; IF: 166.29 sec. -  IF   by  82.22%
  1191.  
  1192. (Seek):  23; CASE: 291.47 sec.; IF: 147.89 sec. -  IF   by  97.09%
  1193. (Exit):  23; CASE:  20.26 sec.; IF:  21.39 sec. -  CASE by   5.58%
  1194. (Total)  23; CASE: 311.73 sec.; IF: 169.28 sec. -  IF   by  84.15%
  1195.  
  1196. (Seek):  24; CASE: 305.90 sec.; IF: 151.36 sec. -  IF   by 102.10%
  1197. (Exit):  24; CASE:  25.39 sec.; IF:  19.21 sec. -  IF   by  32.17%
  1198. (Total)  24; CASE: 331.29 sec.; IF: 170.57 sec. -  IF   by  94.23%
  1199.  
  1200. (Seek):  25; CASE: 306.46 sec.; IF: 151.94 sec. -  IF   by 101.70%
  1201. (Exit):  25; CASE:  18.36 sec.; IF:  19.62 sec. -  CASE by   6.86%
  1202. (Total)  25; CASE: 324.82 sec.; IF: 171.56 sec. -  IF   by  89.33%
  1203.  
  1204. -+-+-+ End of Test +-+-+-
  1205.