VBScript performance tip

Discussions concerning programming of SOFTIMAGE©
User avatar
rray
Moderator
Posts: 1810
Joined: 26 Sep 2009, 13:51
Location: Bonn, Germany

VBScript performance tip

Post by rray » 21 Apr 2011, 13:47

or rather a "warning" for everyone using VBScript

using local object variables in vbscript subs and functions is extremely slow when not using dim!

compare...

Code: Select all

start_t = timer
for n = 0 to 1000
	Set s = getvar()
next
logmessage("time=" & 1000*(timer-start_t) & " milliseconds")

function getvar()
	Set i = Application.Selection
	Set getvar = i
end function
[/size]

outputs
time=492,1875 milliseconds
while

Code: Select all

start_t = timer
for n = 0 to 1000
	Set s = getvar()
next
logmessage("time=" & 1000*(timer-start_t) & " milliseconds")

function getvar()
	Dim i
	Set i = Application.Selection
	Set getvar = i
end function
[/size]

outputs
time=3,90625 milliseconds
only difference is the "Dim i" !

It's probably a good idea to use "option explicit" at the top of the script so you're forced to declare everything
softimage resources section updated Sep 26th 2026