VBScript performance tip

Discussions concerning programming of SOFTIMAGE©
Post Reply
User avatar
rray
Moderator
Posts: 1774
Joined: 26 Sep 2009, 15:51
Location: Bonn, Germany
Contact:

VBScript performance tip

Post by rray » 21 Apr 2011, 15: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 Jan 5th 2024

Post Reply

Who is online

Users browsing this forum: No registered users and 36 guests