WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

How To
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Thoughts on Writing Faster Code


Thoughts on Writing Faster Code Here are some thoughts on the general topic of fast code.
  1. A great many of the winbatch projects I've written take a fairly short time to run. Anything that makes coding more complex could cost me more time in development that it would save at run time.
  2. There are some cases where you really can save time... for example, if you are working with very large strings you would save time by using binary buffers. However it's much more complex to use binary buffers, so unless they are really HUGE strings, see point 1.
  3. In general, the key to faster code is "fewer lines". WinBatch's does most of its work parsing and interpereting commands. Much less in actually executing them.

    An example...

    ;------------------------------------------
    ; Loop 1
    ;------------------------------------------ 
    for x = 1 to 1000
    Root = FileRoot(FileName)
    Ymd = TimeYmdHms() 
    Year = itemExtract(1,Ymd,":")
    Month = itemExtract(2,Ymd,":")
    Day = itemExtract(3,Ymd,":")
    NewName = StrCat(Root,"-",Year,Month,Day,".txt")
    next
    ;------------------------------------------
    ; Loop 2
    ;------------------------------------------ 
    For x = 1 to 1000 
    YmdHms = TimeYmdHms() 
    NewName = StrCat(FileRoot(FileName),"-",itemExtract(1,Ymdhms,":"),itemExtract(2,Ymdhms,":"),itemExtract(3,Ymdhms,":"),".txt")
    next 
    
    On my machine, loop 1 runs in about 1 second. Loop 2 (equivalent code with fewer statements) takes about .6 second.

    But note: were only talking about .4 seconds saved. You'd have to have a really long and complex program to make this worth worrying about.

Making your code easy to understand and maintain would seem, most of the time, a better bet.
Article ID:   W16004
File Created: 2004:03:30:15:42:10
Last Updated: 2004:03:30:15:42:10