LB Booster
General >> General Board >> Effect of variable length on speed
http://lbb.conforums.com/index.cgi?board=general&action=display&num=1511614997

Effect of variable length on speed
Post by Richard Russell on Nov 25th, 2017, 12:03pm

There has been some discussion at the LB Yahoo! group on the effect of variable name length on execution time. Just for interest, these are the results I got from LB 4.5.1 and LBB 3.09 when running the program listed below:

LB 4.5.1:
Long variable name: 798
Short variable name: 793


LBB 3.09:
Long variable name: 115
Short variable name: 98


So the effect of variable name length is more significant in LBB, but even with the long name it runs 7 times faster.

Richard.

Code:
    t1 = time$("ms")
    for i = 1 to 1000000
    next
    t2 = time$("ms")
    for i = 1 to 1000000
      aVeryLongNumericVariableName = i
    next
    t3 = time$("ms")
    for i = 1 to 1000000
      a = i
    next
    t4 = time$("ms")

    print "Long variable name: "; (t3 - t2) - (t2 - t1)
    print "Short variable name: "; (t4 - t3) - (t2 - t1) 

Re: Effect of variable length on speed
Post by RobM on Nov 27th, 2017, 06:03am

Interesting! I would not have thought the length of a variable name would make any difference at all.

Wont change my programming style though, I like to have names that are self descriptive smiley
Re: Effect of variable length on speed
Post by Richard Russell on Nov 27th, 2017, 08:37am

on Nov 27th, 2017, 06:03am, RobM wrote:
I would not have thought the length of a variable name would make any difference at all.

Typically it will make a difference in the case of a language that supports the EVAL function (like Liberty BASIC and BBC BASIC) because the original variable names must be retained in the running program in case they are referenced that way:

Code:
    input "Enter the name of a variable: ";var$
    print "That variable currently has the value ";EVAL(var$) 

BBC BASIC provides a 'compiler directive' that allows the programmer to specify which variable names need to be retained, and which don't (the default), which provides the best of both worlds. But - although in principle it could have done - LBB has not inherited this feature.

Richard.
Re: Effect of variable length on speed
Post by RobM on Nov 27th, 2017, 9:33pm

Thanks. I was wondering why it would make a difference and that pretty much explains it!