Wrox Programmer Forums
BOOK: Stephens' Visual Basic Programming 24-Hour Trainer
This is the forum to discuss the Wrox book Stephens' Visual Basic Programming 24-Hour Trainer by Rod Stephens; ISBN: 978-0-470-94335-9
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Stephens' Visual Basic Programming 24-Hour Trainer section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old September 6th, 2011, 12:38 PM
Authorized User
Join Date: May 2011
Posts: 46
Thanks: 27
Thanked 0 Times in 0 Posts
Default TryIt22 video question

In your TryIt22 video you looped through salary and put 2 debug.assert statements in the loop to check for possible erroneous values. You said in a small system it basically has no noticeable effect on performance but on a large system it could have an effect. Is there a reason you did not put the debug.assert statements in the existing loop where you are calculating the results? That would eliminate the separate debug loop but still give you the debug statements.
Old September 6th, 2011, 02:43 PM
Rod Stephens's Avatar
Wrox Author
Join Date: Jan 2006
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts

Which loop you put these things in doesn't really matter much because you're still doing the check once per item in the loop. I often try to keep these sorts of checking statements as separate as the rest of the code as possible so (1) the purposes of the loops are kept separate and (2) it's easier to comment out the debugging statements later if you want.

There is one very small difference. It's no big deal so if you're happy with that answer stop reading now. If you want a little extra info, read on.
The Debug.Assert statement is removed from the program when you make a release build. In that case, it doesn't add any extra time to the program at all.

If you have a loop that contains only Debug.Assert statements, then the loop is empty (because the Debug.Assert statements have been removed) but it still exists so it takes a little extra time. My computer can run a loop through about 2.2 million loops per second so the extra time is trivial unless you have a really big loop.

In contrast, if you put the Debug.Assert statement inside a loop that you need to run whether or not the debugging statements are removed, then you don't need to execute that extra empty loop, and that will save you a tiny amount of time.

Because the difference is so small, I would use whichever technique makes the most intuitive sense and not worry about the extra millisecond one method will cost over the other.

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
The Following User Says Thank You to Rod Stephens For This Useful Post:
zavodney (September 7th, 2011)
Old September 7th, 2011, 12:59 AM
Authorized User
Join Date: May 2011
Posts: 46
Thanks: 27
Thanked 0 Times in 0 Posts

Thanks, I always like extra info.

Keith Z.

Similar Threads
Thread Thread Starter Forum Replies Last Post
Video Conferencing in C# Bhattachan C# 2005 4 February 18th, 2008 09:07 AM
play online video or video rajanikrishna ASP.NET 2.0 Basics 1 September 17th, 2007 01:01 PM
Video buffering, streaming, and displaying video t CurvyBabe C# 1 March 9th, 2007 01:17 PM
Video Streaming pmishra.mca PHP How-To 1 October 25th, 2006 03:16 AM
Please Help!! Video?? jamyz VB How-To 0 October 15th, 2005 01:22 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.