dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Visual Basic
Expertise: Intermediate
Aug 19, 1997

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


Optimize Code

I often see questions in the VBPJ forum about comparative speeds for different methods of performing actions in code. In many cases, a simple generalization of which is fastest cannot be made. VB's Timer function, however, allows testing your code as you go. Declare a Single variable, TStart! and use this line at the beginning of the code segment you wish to test:
 TStart! = Timer 
At the end of the segment, print the elapsed time to the debug window:
 Debug.print Timer - TStart! 
By doing such time-testing you will be better able to choose between similar ways of doing things. In most cases, for example, the CStr and Str functions are much faster than the Format or Format$ functions. Likewise, the If/Elseif sequence will execute much faster than similar code using the IIf or Choose functions, probably because of the added type checking done by the functions. But IIf and Choose often allow much shorter, clearer subroutines. By performing simple time tests, you can better decide on the appropriate code style.
William Storage
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date