An official Batch Programming blog! To Solve the daily problems with windows and fixing them with little notepad scripts. Unlock the Hidden Secrets of Windows, Learn to crack Software via CMD & Make your own Programming tools. Understand to Manipulate your PC via CMD.

TheBATeam Forum

Rem Vs Colons for b...
 
Notifications
Clear all

[Solved] Rem Vs Colons for batch script comments  


SheWolf99
Posts: 5
(@sheerowwanjiku)
Active Member
Joined: 3 weeks ago

Any logical changes/differences in execution speed if one used the Rem command over the double colons ? What are the pros and cons?

8 Replies
Kvc
Posts: 22
 Kvc
Admin
(@thekvc)
Admin
Joined: 1 year ago

REM-vs-Colon


Just tested out this difference - Yes, I have seen two types of commenting practice in batch files... Both have their Pros and Cons. For technical proof:

I Generated 2 Files - Test-Colon.bat & Test-REM.bat

Both Files contain - Only 10,000 lines of Code (Generated by For Loop/Command) - One contains, comments with Colons and the other one contains commenting with REM command. I tested both with Powershell's following command:

Measure-Command {./Test-REM.bat} and Measure-Command {./Test-Colon.bat}

Tried 3 times - And got the same results as follows: (Time in ms)

Test File

Test-1

Test-2

Test-3

Average Time

Test-REM

3926

3854

3739

3840

Test-Colon

880

898

992

923

So, Basically - If we can see - using Colons (::) for comments in a batch file seems to be almost 4 times (4x) faster than using traditional REM command.

I am Attaching the test files in this post (please check attachments too. 🙂

https://ibb.co/5vxc8db
https://ibb.co/JjSvT1y
https://ibb.co/g753Dzf

Final-Report

The Report is saying 3x - Because, We are only considering the whole number (ignoring the floating points) and depends on the current CPU Load as well. 🙂

Reply
sintrode
Posts: 7
(@sintrode)
Active Member
Joined: 2 months ago

You cannot use :: inside of sets of parentheses - if statements, for loops, etc. This is because :: is technically a label, and it gets parsed at a different time than REM does.

Reply
5 Replies
Kvc
 Kvc
Admin
(@thekvc)
Joined: 1 year ago

Admin
Posts: 22

@sintrode I think,  there is a misunderstanding - The (::) is just a Representation to show that - this part of the script is handling things related to COLON. (I haven't Used colons between parenthesis anywhere in the code).

Reply
sintrode
(@sintrode)
Joined: 2 months ago

Active Member
Posts: 7

@thekvc - I never said you did. SheWolf99 asked what pros and cons were of using each one, and a huge con of :: is that you can't freely use it everywhere in a script.

Reply
Kvc
 Kvc
Admin
(@thekvc)
Joined: 1 year ago

Admin
Posts: 22

@sintrode Yes, That is right - I have experienced some of my scripts closing unexpectedly because of the use of :: for Comments. But, Then I found a solution as if you use a colon for commenting - Put a space after :: and then write the comment - this will avoid crashing the script. The example of this would be as:

:: This is Comment

instead of...

::This is a comment

This little change avoids breaking of scripts (I experienced it in a few of my programs) - but, later - i decided to use the traditional REM command for commenting (to avoid taking any chances to change my code later).

but, after experimenting with this question - I am going to change my decision for REM command. 

Reply
sintrode
(@sintrode)
Joined: 2 months ago

Active Member
Posts: 7

@thekvc - That only works because you got lucky. 

 

:: Comment

is how I do all of my comments, and I've experienced it failing in code blocks firsthand.

 

Reply
Kvc
 Kvc
Admin
(@thekvc)
Joined: 1 year ago

Admin
Posts: 22

@sintrode Yup, So this answers @SheWolf99 that - The Pro is: SPEED

And, the Con is: RISK of Program Crash

Reply
SheWolf99
Posts: 5
(@sheerowwanjiku)
Active Member
Joined: 3 weeks ago

That was fast, thanks @kvc and @sintrode

Reply
Share:

© 2020 TheBATeam

Our Core Values   /   Terms & Conditions   /   Privacy Policy   /   Why Register?

Theme by Anders Norén