home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / batch / library / batutl2 / fastbat.txt < prev    next >
Text File  |  1986-08-29  |  6KB  |  144 lines

  1.                                   FASTBAT.TXT
  2.                             SPEEDING UP BATCH FILES
  3.                          by Bob Unferth   Wilmette, IL
  4.  
  5.        Batch files make life a lot easier, but they are very slow.  Even
  6.        when using batch files in RAM disks, execution time is quite
  7.        noticeable.  It reminds me of the time when a batch file meant a
  8.        batch of cards.  The techniques described here reduce the time
  9.        required to execute batch file by as much as an order of magnitude.
  10.  
  11.        Execution time is closely related to the number of lines rather
  12.        than the number of characters.  To save time put as many commands
  13.        on one line as possible.  Some ways to do this:
  14.  
  15.        1. Instead of using a lot of lines for remarks, put what you have
  16.        to say in a file and issue the batch command TYPE FILE.  TYPing a
  17.        file takes less than 30% as long as echoing the same information
  18.        from a batch file.
  19.  
  20.        2. Instead of using a lot of lines to issue commands, put all the
  21.        commands in a FOR subcommand.  For instance, your autoexec.bat file
  22.        might start out
  23.                            fastdisk
  24.                            parint
  25.                            scrnsave
  26.                            spool 7
  27.                            sk
  28.                            c:
  29.  
  30.        Instead, just say
  31.  
  32.        for %%f in (fastdisk parint scrnsave spool:7 sk c:) do %%f
  33.  
  34.        This reduces six lines to one.  In Dos 2.1, but not in 3.0, you can
  35.        eliminate spaces and slightly decrease execution time like this:
  36.  
  37.        for %%fin(fastdisk parint scrnsave spool:7 sk c:)do%%f
  38.  
  39.        Note the colon between spool and 7. You can't have any spaces
  40.        within the parentheses except to denote the beginning of a new
  41.        command.
  42.  
  43.        3. When copying files use the FOR subcommand and wild cards like
  44.        this:
  45.  
  46.        for %%fin(print v sp)docopy a:%%f???.*
  47.  
  48.        The FOR subcommand does not support wild cards within the
  49.        parentheses.
  50.  
  51.        [PUBLIC SOFTWARE LIBRARY NOTE: Barry Simon of CalTech tells us:
  52.        "The whole beauty of for..in..do is that it accepts wild cards
  53.        contrary to the claim in fastbat.txt (although I did decide to
  54.        check DOS 2 again and learned that while dos 3.x allows both
  55.        multiple entries in the (...) with each entry wildcarded, DOS 2.x
  56.        only allows multiple unwildcarded entires or a single wildcarded
  57.        entries."]
  58.  
  59.        How much time the FOR subcommand will save, if any, depends on how
  60.        the disk buffers are used while the subcommand is being executed.
  61.        DOS remembers the entire subcommand.  It doesn't have to go back to
  62.        disk to read more of the subcommand as it goes along.  But DOS
  63.        doesn't remember the contents of the batch file unless it is held
  64.        in disk buffers.  Whether or not the disk buffers keep the contents
  65.        of the batch file depends on what you're doing between batch
  66.        commands.
  67.  
  68.  
  69.  
  70.  
  71.  
  72.                               FASTBAT.TXT  page 2
  73.  
  74.        4. The IF subcommand supports conditional commands and the FOR
  75.        subcommand.  For instance, you might want to see if a file exists
  76.        and, if it does, to run several programs and then to return to the
  77.        menu; or, if it doesn't to display a message and return to the
  78.        menu.  A batch file for this task might look like this:
  79.  
  80.          If exist myufile goto programs
  81.          echo File does not exist.  Try again.
  82.          d:menu
  83.          :programs
  84.          myprog.ram
  85.          second.prg
  86.          third
  87.          d:menu
  88.  
  89.        But it will run faster like this:
  90.  
  91.        If exist myfile for %%fin(myprog.ram second.prg third d:menu)do%%f
  92.        for %%fin(echo d:menu)do%%f File does not exist.  Try again,
  93.  
  94.        5. When a command processor is or another batch file is invoked,
  95.        batch processing for the first batch is terminated.  You don't need
  96.        to exit the batch file.  For example, in the batch file fragment
  97.        below, the command GOTO GETOUT (and probably the label :GETOUT) is
  98.        unnecessary and will increase execution time in some cases:
  99.                                 ..
  100.                              command c:
  101.                              goto to getout
  102.                                 ..
  103.                                 ..
  104.                              :getout.
  105.  
  106.        6. A fast way to get out of the middle of a batch file is to issue
  107.        a command for another batch file, say a file called exit.  EXIT can
  108.        contain only the command REM or just a dot or better yet nothing.
  109.        A file that contains nothing doesn't take up any disk space.  You
  110.        can create such a file with another batch file, say autoexec.bat,
  111.        by inserting this command
  112.  
  113.        for %%fin(echo rem)do%%f >d:exit.bat
  114.  
  115.        The rem part of the command can be any command that doesn't look
  116.        for parameters on the command line, e.g. cls or pause or sk.
  117.  
  118.        7. Of course, running batch files from a RAM disk is a big help.
  119.        It's sometimes worth transferring control to a batch file that has
  120.        been copied onto your RAM disk.  The time required for handling the
  121.        batch operations in a RAM disk is less than a third of that
  122.        required for a floppy.
  123.  
  124.        8. Putting an end-of-file marker (ASCII 26 or Control Z) on the
  125.        same line and immediately after the last command, will prevent
  126.        annoying multiple prompts at the end of batch processing.
  127.  
  128.  
  129.  
  130.  
  131.  
  132.                    This disk copy provided as a service of
  133.  
  134.                         The Public (Software) Library
  135.  
  136.          For a copy of the latest monthly software library newsletter
  137.          and program directory, send a self-addressed, stamped (with
  138.          two stamps), legal-size envelope or send $1 to
  139.  
  140.                         The Public (Software) Library
  141.                                 P.O.Box 35705
  142.                                   Dept. 271
  143.                            Houston, TX 77235-5705
  144.