Hi there,
Just found these forums and my first post, so hi all

I'm doing some work with vbscript just now and had a quick question I hope
somebody could help with...

Say I have a few functions for accessing a database e.g. openDBConn,
closeDBConn, openRs, closeRs, getRsAsArray, executeSql, getDbConnString etc

I could put these functions in to an include file "incDbHelper.asp" and
include the file in any page that needs database functionality... or I could
create a class "clsDbhelper.asp" which again I would include in any page that
needs it. Now once the files have been included, to access the functions I
could do:

executeSQL("select * form table")

or

(if my db class is called Database)

set db = new Database
db.executeSQL("select * form table")

So my question is what is the best method? Using a class seems like extra
overhead for nothing? I've had a search around google but couldn't find
anything on performance issues when using classes. Does anybody have an
experience they could help me out with?

Thanks in advance for any help

Re: Are vbscript classes fast? by Tim

Tim
Sat May 03 02:00:35 CDT 2008

Big plus with using a class is encapsulation of all methods/variables
defined in it, so reducing risk of "collisions" - particularly with a large
number of includes. It's really just a few more lines of code, so not a big
deal for something you can use over and over..

I don't think performance is an issue here.

Tim

"atwork8" <atwork8@discussions.microsoft.com> wrote in message
news:88887148-16BF-4A60-AB8F-23ED3D33454A@microsoft.com...
> Hi there,
> Just found these forums and my first post, so hi all
>
> I'm doing some work with vbscript just now and had a quick question I hope
> somebody could help with...
>
> Say I have a few functions for accessing a database e.g. openDBConn,
> closeDBConn, openRs, closeRs, getRsAsArray, executeSql, getDbConnString
> etc
>
> I could put these functions in to an include file "incDbHelper.asp" and
> include the file in any page that needs database functionality... or I
> could
> create a class "clsDbhelper.asp" which again I would include in any page
> that
> needs it. Now once the files have been included, to access the functions I
> could do:
>
> executeSQL("select * form table")
>
> or
>
> (if my db class is called Database)
>
> set db = new Database
> db.executeSQL("select * form table")
>
> So my question is what is the best method? Using a class seems like extra
> overhead for nothing? I've had a search around google but couldn't find
> anything on performance issues when using classes. Does anybody have an
> experience they could help me out with?
>
> Thanks in advance for any help



Re: Are vbscript classes fast? by ekkehard

ekkehard
Sat May 03 02:37:44 CDT 2008

atwork8 schrieb:
> Hi there,
> Just found these forums and my first post, so hi all
>
> I'm doing some work with vbscript just now and had a quick question I hope
> somebody could help with...
>
> Say I have a few functions for accessing a database e.g. openDBConn,
> closeDBConn, openRs, closeRs, getRsAsArray, executeSql, getDbConnString etc
>
> I could put these functions in to an include file "incDbHelper.asp" and
> include the file in any page that needs database functionality... or I could
> create a class "clsDbhelper.asp" which again I would include in any page that
> needs it. Now once the files have been included, to access the functions I
> could do:
>
> executeSQL("select * form table")

I think you describe the functional approach in a too simple way. While you could
argue that your application uses just one connection and functions like executeSQL
could use a global variable to hold this connection, more elaborate functions will
need a lot of additional parameters to pass objects to work with and information
about the current state of a complex process to those methods. Doing that in an
impromptu way (using globals, changing signatures/prototypes all the time) will
lead to desaster.

Using classes will help you to do your task in a more organized way, because the
object in/of the method call

db.executeSQL "select * form table" ' no param list () allowed here

will hold everything the method needs beside the SQL statement.

>
> or
>
> (if my db class is called Database)
>
> set db = new Database
> db.executeSQL("select * form table")
>
> So my question is what is the best method? Using a class seems like extra
> overhead for nothing? I've had a search around google but couldn't find
> anything on performance issues when using classes. Does anybody have an
> experience they could help me out with?

As you use such classes for database work, the overhead of the class approach
(if any) won't have noticeable impact on your application.

The extra *work* you'll have to put into learning/implementing classes will be well
spend.


>
> Thanks in advance for any help

Re: Are vbscript classes fast? by Alexander

Alexander
Sat May 03 09:54:27 CDT 2008

atwork8 schrieb:

> Say I have a few functions for accessing a database e.g. openDBConn,
> closeDBConn, openRs, closeRs, getRsAsArray, executeSql, getDbConnString etc
>
> I could put these functions in to an include file "incDbHelper.asp" and
> include the file in any page that needs database functionality...

> or I could create a class "clsDbhelper.asp" which again I would include in any
page that
> needs it. Now once the files have been included, to access the functions I
> could do:
>
> executeSQL("select * form table")
>
> or
>
> (if my db class is called Database)
>
> set db = new Database
> db.executeSQL("select * form table")
>
> So my question is what is the best method? Using a class seems like extra
> overhead for nothing? I've had a search around google but couldn't find
> anything on performance issues when using classes. Does anybody have an
> experience they could help me out with?

If you put tool functions into a class the only benefit
you have is encapsulation and better structure, which is
a gain when the project is big.
The performance aspect doesn't matter to my opinion in
database-context, cause the time needed to create the object
is insignificant as compared to time needed to fetch, read
and update records. Of course the class _is_ an overhead, so
you will loose some µsecs <g>.

Class usage is really useful, when you deal with multiple "entities"
of the same kind, that all have their own private data to be
manipulated, such as a customer, a booking and so on.
Code will become more readable and more "logic" to my experience.
As for the DB wrapper it's a matter of taste, jm2c.

MfG,
Alex

Re: Are vbscript classes fast? by atwork8

atwork8
Sat May 03 12:05:02 CDT 2008

Hi Guys,

Thanks for the help :o)

The example I provided was just for illustration . I really just wanted to
know if i would see a significant performance difference in an asp
application that was written in classes rather than include files with
functions... all else aside collisions etc

What do you think?

Re: Are vbscript classes fast? by Tim

Tim
Sat May 03 14:16:31 CDT 2008

I don't think it's going to make any difference. You're already creating a
bunch of objects (connections, recordsets, etc).

If in doubt though, it's easy to test.

Tim

"atwork8" <atwork8@discussions.microsoft.com> wrote in message
news:6C05787C-FFCE-44C5-8644-BDEBA08D4490@microsoft.com...
> Hi Guys,
>
> Thanks for the help :o)
>
> The example I provided was just for illustration . I really just wanted to
> know if i would see a significant performance difference in an asp
> application that was written in classes rather than include files with
> functions... all else aside collisions etc
>
> What do you think?



Re: Are vbscript classes fast? by Al

Al
Sun May 04 12:17:55 CDT 2008

I agree. If you need extreme speed, use a compiled language. If a scripting
language will do the job, structure it in such a way as to save time in the
development and maintenance phases rather than trying to tweak it to speed
it up in the execution phase.

/Al

"Tim Williams" <timjwilliams at gmail dot com> wrote in message
news:OzNdpIVrIHA.3900@TK2MSFTNGP05.phx.gbl...
>I don't think it's going to make any difference. You're already creating a
>bunch of objects (connections, recordsets, etc).
>
> If in doubt though, it's easy to test.
>
> Tim
>
> "atwork8" <atwork8@discussions.microsoft.com> wrote in message
> news:6C05787C-FFCE-44C5-8644-BDEBA08D4490@microsoft.com...
>> Hi Guys,
>>
>> Thanks for the help :o)
>>
>> The example I provided was just for illustration . I really just wanted
>> to
>> know if i would see a significant performance difference in an asp
>> application that was written in classes rather than include files with
>> functions... all else aside collisions etc
>>
>> What do you think?
>
>



Re: Are vbscript classes fast? by Alex

Alex
Wed May 07 14:14:29 CDT 2008

Hitching a ride here... ;)

Basically, what they said. I played around with this a lot about 5-6 years
ago - made some posts on obscure parts of it to this and the WSH newsgroup,
but most of it is heavy wading with little useful results. Here are a few
points that may have some value.

+ First of all, what Al said about structuring it ironically is the best way
to gain performance in the end. Well-structured code is easy to follow and
extend without jumping through all sorts of hoops that add performance
problems and hidden bugs.

+ Generally speaking, there is an overhead cost to creating a new scope, be
it a function or a class, but the mere act of creating the scope is fairly
rapid. I compared a generic function that just returned an empty value
written in script and written as a method of a compiled component, and not
surprisingly, the script function was slower by a factor of two - most
likely due to scope creation. Even that was miniscule, and on a modern PC is
difficult for me to measure - roughly 3 microseconds in script on a dual
core AMD 2600+. You can trim this down by explicitly declaring all variables
and using Option Explicit in the script as well.

+ Object creation is pretty expensive, more expensive than calling a
function, even though calling into an object is cheaper. The MOST expensive
way to create an object is to use WScript.CreateObject or
Server.CreateObject instead of the native CreateObject in VBScript. This is
due to extra things done for event creation I believe; the native
CreateObject generally chops a third off of creation time. This is most
important if you need to continually create objects, and also means that
hanging on to objects is a viable way of shaving time if you really need to.

+ The critical choice between using functions and classes comes down to one
thing: does the function need to perform the same tasks repeatedly? If you
need to recreate an object and declare a couple of constants each time you
call a function, you're going to have the scoping and creation overhead on
each function call. If you do this consistently a couple of times or more in
each run of the code, then you're already at the point where pushing the
code over into a class gives you a performance gain. This is actually an
ideal situation because classes are actually designed to simplify repetitive
complexity.

"Al Dunbar" <AlanDrub@hotmail.com.nospaam> wrote in message
news:elGD4wgrIHA.3780@TK2MSFTNGP03.phx.gbl...
> I agree. If you need extreme speed, use a compiled language. If a
> scripting language will do the job, structure it in such a way as to save
> time in the development and maintenance phases rather than trying to tweak
> it to speed it up in the execution phase.
>
> /Al
>
> "Tim Williams" <timjwilliams at gmail dot com> wrote in message
> news:OzNdpIVrIHA.3900@TK2MSFTNGP05.phx.gbl...
>>I don't think it's going to make any difference. You're already creating
>>a bunch of objects (connections, recordsets, etc).
>>
>> If in doubt though, it's easy to test.
>>
>> Tim
>>
>> "atwork8" <atwork8@discussions.microsoft.com> wrote in message
>> news:6C05787C-FFCE-44C5-8644-BDEBA08D4490@microsoft.com...
>>> Hi Guys,
>>>
>>> Thanks for the help :o)
>>>
>>> The example I provided was just for illustration . I really just wanted
>>> to
>>> know if i would see a significant performance difference in an asp
>>> application that was written in classes rather than include files with
>>> functions... all else aside collisions etc
>>>
>>> What do you think?
>>
>>
>
>

Re: Are vbscript classes fast? by Al

Al
Sat May 10 11:33:06 CDT 2008


"Alex K. Angelopoulos" <aka(at)mvps.org> wrote in message
news:%23tq4SaHsIHA.5580@TK2MSFTNGP04.phx.gbl...
> Hitching a ride here... ;)

Welcome aboard!

> Basically, what they said. I played around with this a lot about 5-6 years
> ago - made some posts on obscure parts of it to this and the WSH
> newsgroup, but most of it is heavy wading with little useful results. Here
> are a few points that may have some value.
>
> + First of all, what Al said about structuring it ironically is the best
> way to gain performance in the end. Well-structured code is easy to follow
> and extend without jumping through all sorts of hoops that add performance
> problems and hidden bugs.

One day I will write a book about how to structure script code "ironically"!
;-)

> + Generally speaking, there is an overhead cost to creating a new scope,
> be it a function or a class, but the mere act of creating the scope is
> fairly rapid. I compared a generic function that just returned an empty
> value written in script and written as a method of a compiled component,
> and not surprisingly, the script function was slower by a factor of two -
> most likely due to scope creation. Even that was miniscule, and on a
> modern PC is difficult for me to measure - roughly 3 microseconds in
> script on a dual core AMD 2600+. You can trim this down by explicitly
> declaring all variables and using Option Explicit in the script as well.

Useful information, however I find that factor of two rather flattering
towards the scripted function. The OP should also realize that moving some
of his code into compiled components will not cut the overall run-time of
his script in half. If 2% of the runtime of the script is taken up with
calling a function, that will reduce that part of the "time cost" to 1%,
thereby speeding up the overall operation of the script by a whopping 1%
(100% ==> 99%).

> + Object creation is pretty expensive, more expensive than calling a
> function, even though calling into an object is cheaper. The MOST
> expensive way to create an object is to use WScript.CreateObject or
> Server.CreateObject instead of the native CreateObject in VBScript. This
> is due to extra things done for event creation I believe; the native
> CreateObject generally chops a third off of creation time.

A very useful observation, and one I was not aware of.

> This is most important if you need to continually create objects, and
> also means that hanging on to objects is a viable way of shaving time if
> you really need to.

Another useful observation. Unfortunately, this can result in reducing the
"structure" of the script by introducing more global object variables if not
done in a disciplined manner.

/Al

> + The critical choice between using functions and classes comes down to
> one thing: does the function need to perform the same tasks repeatedly? If
> you need to recreate an object and declare a couple of constants each time
> you call a function, you're going to have the scoping and creation
> overhead on each function call. If you do this consistently a couple of
> times or more in each run of the code, then you're already at the point
> where pushing the code over into a class gives you a performance gain.
> This is actually an ideal situation because classes are actually designed
> to simplify repetitive complexity.
>
> "Al Dunbar" <AlanDrub@hotmail.com.nospaam> wrote in message
> news:elGD4wgrIHA.3780@TK2MSFTNGP03.phx.gbl...
>> I agree. If you need extreme speed, use a compiled language. If a
>> scripting language will do the job, structure it in such a way as to save
>> time in the development and maintenance phases rather than trying to
>> tweak it to speed it up in the execution phase.
>>
>> /Al
>>
>> "Tim Williams" <timjwilliams at gmail dot com> wrote in message
>> news:OzNdpIVrIHA.3900@TK2MSFTNGP05.phx.gbl...
>>>I don't think it's going to make any difference. You're already creating
>>>a bunch of objects (connections, recordsets, etc).
>>>
>>> If in doubt though, it's easy to test.
>>>
>>> Tim
>>>
>>> "atwork8" <atwork8@discussions.microsoft.com> wrote in message
>>> news:6C05787C-FFCE-44C5-8644-BDEBA08D4490@microsoft.com...
>>>> Hi Guys,
>>>>
>>>> Thanks for the help :o)
>>>>
>>>> The example I provided was just for illustration . I really just wanted
>>>> to
>>>> know if i would see a significant performance difference in an asp
>>>> application that was written in classes rather than include files with
>>>> functions... all else aside collisions etc
>>>>
>>>> What do you think?
>>>
>>>
>>
>>



Re: Are vbscript classes fast? by Alex

Alex
Sun May 11 06:23:38 CDT 2008

"Al Dunbar" <AlanDrub@hotmail.com.nospaam> wrote in message
news:Oi3ONBssIHA.4876@TK2MSFTNGP02.phx.gbl...
>
> "Alex K. Angelopoulos" <aka(at)mvps.org> wrote in message
> news:%23tq4SaHsIHA.5580@TK2MSFTNGP04.phx.gbl...

>> First of all, what Al said about structuring it ironically ...
> One day I will write a book about how to structure script code
> "ironically"! ;-)


That word order thing trips me up all the time. ;)

Just don't overspecialize. I recommend starting out with a book of coding
jokes. :D


Re: Are vbscript classes fast? by Al

Al
Sun May 11 11:56:08 CDT 2008


"Alex K. Angelopoulos" <aka(at)mvps.org> wrote in message
news:OHzs5l1sIHA.5872@TK2MSFTNGP04.phx.gbl...
> "Al Dunbar" <AlanDrub@hotmail.com.nospaam> wrote in message
> news:Oi3ONBssIHA.4876@TK2MSFTNGP02.phx.gbl...
>>
>> "Alex K. Angelopoulos" <aka(at)mvps.org> wrote in message
>> news:%23tq4SaHsIHA.5580@TK2MSFTNGP04.phx.gbl...
>
>>> First of all, what Al said about structuring it ironically ...
>> One day I will write a book about how to structure script code
>> "ironically"! ;-)
>
>
> That word order thing trips me up all the time. ;)

Word order, or a shortage of commas. You seem to have the opposite of an
affliciton my friend has, whose thesis supervisor said he imagined the
student sitting at his desk with a box full of commas to sprinkle on his
work.

> Just don't overspecialize. I recommend starting out with a book of coding
> jokes. :D

In other words: don't quit your day job! Thanks for more useful advice...
;-)

/Al