REM slowing down BAT execution

25 Mar

This may come to a surprise to some of us, but about 2 years back engineering guys implemented a batch logon script which is run on in Windows XP workstations. The domain controllers are centralised to Singapore and the small branches (e.g. Thailand) logon to the DC in Singapore.

A strange thing happened at logon, it was taking a few minutes to execution. We all thought that it was the bandwidth was causing the problem, it couldn’t be the XP machines, since they are new and no way would execute a simple logon script that slowly. However, the bandwidth was found to be acceptable and so I had a look at the logon script. Nothing unusual with it, its a few lines and calls some other routines.

So I modified the logon file and piped “time /t” commands between codes to see where it was slowing down. The result was interesting, it took a few minutes to execute the starting portion of the logon script. When I looked at it, there was no routines or programs being executed, only REM as part of documentation and change history. It was just too weird, I had thought that REM would not cause any penalties to the execution cycles. Disbelieving myself, I took all the REM statements out and the logon script went through at normal speed!

This was 2 years ago, so I don’t know if it has changed much, but my conclusion went something like this:

  • REM statements are evaluated in Windows and takes up cycle time.We don’t notice them most of the time because of the speed of execution. However, because the batch file was run from a moderate to low bandwidth location across a WAN, this becomes obvious.
  • The execution engine for BAT (legacy DOS) and CMD are different. The logon file was running as a BAT file uses possibly a 16-bit DOS engine, whereas CMD used the 32-bit engine. I tested the same batch file by renaming it to CMD and it ran perfectly. (I cannot find any reference for this, so I might be wrong).

Posted by on March 25, 2007 in Scripts, Windows, Windows CMD



4 responses to “REM slowing down BAT execution

  1. Hisham

    May 11, 2007 at 6:47 am

    Hummm … so does CMD retains the commands as in BAT?

  2. saltwetfish

    May 11, 2007 at 4:14 pm

    The commands in a BAT file is the same as a CMD file. You should be able to rename a CMD file to BAT and vice versa and they both can still run.

  3. wobblysteve

    June 7, 2007 at 11:56 am

    You couldn’t have made that one up……!!!!!

    We were having a similar problem with a legacy dos app – having migrated it from a Novell environment to a W2k3 environment.

    Various “tecchies” within group had “had a go” at the problem, from several different directions (ntvdm.exe, switching off HT, etc.) – but to no avail.

    Googled your article – read it, didn’t believe it – figured “what harm could it do!!” – HEY PRESTO happy end users !!!!!

    Removed both REM lines in .bat file for app, and renamed it to .cmd file – instant improvement in response time..

    Many many thanks!

    Kindest Regards


  4. saltwetfish

    June 7, 2007 at 4:36 pm

    Hi WS,

    I am glad I was able to help out. đŸ™‚


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: