Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Speed up VBA - using class objects

Hi there,

I've read quite a few of the "How do I speed up my VBA" posts, and
they've contained a few useful tips that I'll be using... a more
specific question...

I'm working on a monte carlo simulator whose functionality is written
pretty much entirely in a single loooong method. I've knocked a couple
of hours of it's runngin time already, and am at the point of
clutching at straws to get rid of a few more minutes...

I heard from someone that splitting my code up and approaching it from
a more OO perspective, using excel user defined classes might speed it
up. Has anyone got an opinion on this?

Any other ideas, beyond disabling screen updating would be greatfully
recieved :)

Cheers

Chris

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Speed up VBA - using class objects

From my experience OO is not going to speed things up materially. It could
actually slow things down.

From the stand point of "One Big Procedure", oddly enough that will normally
be faster than a bunch of small procedures. Especialy if you are calling the
sub procedures in a loop. This is because each time the procedure is called
memory needs to be created on the stack and then destroyed when it is
finished. that does not take a significant amount of time but if you have it
in a loop that is called thousands of times it starts to add up.

The biggest things to speed up code a
Use good coding practices such as declaring all of your variables (and not
as variants). Don't use New in a dim statement, ...
Turn off screenUpdating, set calculation to manual and disable events.
Each of these depends on what you are doing as to whether they will make any
difference at all.
Avoid using Select in your code. Using workbook, worksheet and range
objects you do not need to use selects 99.9% of the time.
There are a bunch of very marginal gains to be had by doing things like
declaring your variables as Long instead of Integer (you system actually
converts the int to a long and back again sincy you work in 32 bit) and
having your loops count down to 0 instead of up to some arbitrary number
(computers recognize zero faster than any other number so the comparison is
easier).
Finally you can convert your code to a VB6 bas module if you have a copy
of VB6 and then access the compiled code which will run faster than the
equivalent VBA code.

Note that some of those are more difficult than others and some show only
marginal increases in speed. If you want more specific help you will need to
post your code.

--
HTH...

Jim Thomlinson


" wrote:

Hi there,

I've read quite a few of the "How do I speed up my VBA" posts, and
they've contained a few useful tips that I'll be using... a more
specific question...

I'm working on a monte carlo simulator whose functionality is written
pretty much entirely in a single loooong method. I've knocked a couple
of hours of it's runngin time already, and am at the point of
clutching at straws to get rid of a few more minutes...

I heard from someone that splitting my code up and approaching it from
a more OO perspective, using excel user defined classes might speed it
up. Has anyone got an opinion on this?

Any other ideas, beyond disabling screen updating would be greatfully
recieved :)

Cheers

Chris


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Speed up VBA - using class objects

and having your loops count down to 0 instead of up to some arbitrary
number


That is an interesting one, never thought of that.
Have you done some timings to see the difference?

RBS

"Jim Thomlinson" wrote in message
...
From my experience OO is not going to speed things up materially. It could
actually slow things down.

From the stand point of "One Big Procedure", oddly enough that will
normally
be faster than a bunch of small procedures. Especialy if you are calling
the
sub procedures in a loop. This is because each time the procedure is
called
memory needs to be created on the stack and then destroyed when it is
finished. that does not take a significant amount of time but if you have
it
in a loop that is called thousands of times it starts to add up.

The biggest things to speed up code a
Use good coding practices such as declaring all of your variables (and
not
as variants). Don't use New in a dim statement, ...
Turn off screenUpdating, set calculation to manual and disable events.
Each of these depends on what you are doing as to whether they will make
any
difference at all.
Avoid using Select in your code. Using workbook, worksheet and range
objects you do not need to use selects 99.9% of the time.
There are a bunch of very marginal gains to be had by doing things like
declaring your variables as Long instead of Integer (you system actually
converts the int to a long and back again sincy you work in 32 bit) and
having your loops count down to 0 instead of up to some arbitrary number
(computers recognize zero faster than any other number so the comparison
is
easier).
Finally you can convert your code to a VB6 bas module if you have a copy
of VB6 and then access the compiled code which will run faster than the
equivalent VBA code.

Note that some of those are more difficult than others and some show only
marginal increases in speed. If you want more specific help you will need
to
post your code.

--
HTH...

Jim Thomlinson


" wrote:

Hi there,

I've read quite a few of the "How do I speed up my VBA" posts, and
they've contained a few useful tips that I'll be using... a more
specific question...

I'm working on a monte carlo simulator whose functionality is written
pretty much entirely in a single loooong method. I've knocked a couple
of hours of it's runngin time already, and am at the point of
clutching at straws to get rid of a few more minutes...

I heard from someone that splitting my code up and approaching it from
a more OO perspective, using excel user defined classes might speed it
up. Has anyone got an opinion on this?

Any other ideas, beyond disabling screen updating would be greatfully
recieved :)

Cheers

Chris



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Speed up VBA - using class objects

A simple test doesn't show any difference:

Option Explicit
Private Declare Function timeGetTime Lib "winmm.dll" () As Long
Private lStartTime As Long

Sub StartSW()
lStartTime = timeGetTime()
End Sub

Sub StopSW(Optional ByRef strMessage As Variant = "")
MsgBox "Done in " & timeGetTime() - lStartTime & " msecs", , strMessage
End Sub

Sub test()

Dim i As Long
Dim n As Long
Dim arr(0 To 1000000) As Long

StartSW
For i = 0 To 1000000
n = arr(i)
Next i
StopSW "counting up"

StartSW
For i = 1000000 To 0 Step -1
n = arr(i)
Next i
StopSW "counting down to zero"

End Sub


RBS


"RB Smissaert" wrote in message
...
and having your loops count down to 0 instead of up to some arbitrary
number


That is an interesting one, never thought of that.
Have you done some timings to see the difference?

RBS

"Jim Thomlinson" wrote in
message ...
From my experience OO is not going to speed things up materially. It
could
actually slow things down.

From the stand point of "One Big Procedure", oddly enough that will
normally
be faster than a bunch of small procedures. Especialy if you are calling
the
sub procedures in a loop. This is because each time the procedure is
called
memory needs to be created on the stack and then destroyed when it is
finished. that does not take a significant amount of time but if you have
it
in a loop that is called thousands of times it starts to add up.

The biggest things to speed up code a
Use good coding practices such as declaring all of your variables (and
not
as variants). Don't use New in a dim statement, ...
Turn off screenUpdating, set calculation to manual and disable events.
Each of these depends on what you are doing as to whether they will make
any
difference at all.
Avoid using Select in your code. Using workbook, worksheet and range
objects you do not need to use selects 99.9% of the time.
There are a bunch of very marginal gains to be had by doing things like
declaring your variables as Long instead of Integer (you system actually
converts the int to a long and back again sincy you work in 32 bit) and
having your loops count down to 0 instead of up to some arbitrary number
(computers recognize zero faster than any other number so the comparison
is
easier).
Finally you can convert your code to a VB6 bas module if you have a copy
of VB6 and then access the compiled code which will run faster than the
equivalent VBA code.

Note that some of those are more difficult than others and some show only
marginal increases in speed. If you want more specific help you will need
to
post your code.

--
HTH...

Jim Thomlinson


" wrote:

Hi there,

I've read quite a few of the "How do I speed up my VBA" posts, and
they've contained a few useful tips that I'll be using... a more
specific question...

I'm working on a monte carlo simulator whose functionality is written
pretty much entirely in a single loooong method. I've knocked a couple
of hours of it's runngin time already, and am at the point of
clutching at straws to get rid of a few more minutes...

I heard from someone that splitting my code up and approaching it from
a more OO perspective, using excel user defined classes might speed it
up. Has anyone got an opinion on this?

Any other ideas, beyond disabling screen updating would be greatfully
recieved :)

Cheers

Chris




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Speed up VBA - using class objects

Thanks guys - some useful replys... will investigate the bas module -
that sounds interesting..

Cheers

Chris


On May 31, 1:13 pm, "RB Smissaert"
wrote:
A simple test doesn't show any difference:

Option Explicit
Private Declare Function timeGetTime Lib "winmm.dll" () As Long
Private lStartTime As Long

Sub StartSW()
lStartTime = timeGetTime()
End Sub

Sub StopSW(Optional ByRef strMessage As Variant = "")
MsgBox "Done in " & timeGetTime() - lStartTime & " msecs", , strMessage
End Sub

Sub test()

Dim i As Long
Dim n As Long
Dim arr(0 To 1000000) As Long

StartSW
For i = 0 To 1000000
n = arr(i)
Next i
StopSW "counting up"

StartSW
For i = 1000000 To 0 Step -1
n = arr(i)
Next i
StopSW "counting down to zero"

End Sub

RBS

"RB Smissaert" wrote in message

...



and having your loops count down to 0 instead of up to some arbitrary
number


That is an interesting one, never thought of that.
Have you done some timings to see the difference?


RBS


"Jim Thomlinson" wrote in
...
From my experience OO is not going to speed things up materially. It
could
actually slow things down.


From the stand point of "One Big Procedure", oddly enough that will
normally
be faster than a bunch of small procedures. Especialy if you are calling
the
sub procedures in a loop. This is because each time the procedure is
called
memory needs to be created on the stack and then destroyed when it is
finished. that does not take a significant amount of time but if you have
it
in a loop that is called thousands of times it starts to add up.


The biggest things to speed up code a
Use good coding practices such as declaring all of your variables (and
not
as variants). Don't use New in a dim statement, ...
Turn off screenUpdating, set calculation to manual and disable events.
Each of these depends on what you are doing as to whether they will make
any
difference at all.
Avoid using Select in your code. Using workbook, worksheet and range
objects you do not need to use selects 99.9% of the time.
There are a bunch of very marginal gains to be had by doing things like
declaring your variables as Long instead of Integer (you system actually
converts the int to a long and back again sincy you work in 32 bit) and
having your loops count down to 0 instead of up to some arbitrary number
(computers recognize zero faster than any other number so the comparison
is
easier).
Finally you can convert your code to a VB6 bas module if you have a copy
of VB6 and then access the compiled code which will run faster than the
equivalent VBA code.


Note that some of those are more difficult than others and some show only
marginal increases in speed. If you want more specific help you will need
to
post your code.


--
HTH...


Jim Thomlinson


" wrote:


Hi there,


I've read quite a few of the "How do I speed up my VBA" posts, and
they've contained a few useful tips that I'll be using... a more
specific question...


I'm working on a monte carlo simulator whose functionality is written
pretty much entirely in a single loooong method. I've knocked a couple
of hours of it's runngin time already, and am at the point of
clutching at straws to get rid of a few more minutes...


I heard from someone that splitting my code up and approaching it from
a more OO perspective, using excel user defined classes might speed it
up. Has anyone got an opinion on this?


Any other ideas, beyond disabling screen updating would be greatfully
recieved :)


Cheers


Chris- Hide quoted text -


- Show quoted text -





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Speed up VBA - using class objects

Classes will most likely slow things down, not speed them up. The value of
classes is rarely to get a performance boost.

Most savings will be achieved in the design, look at the overall objectives
and see if the approach can be modified to improve the performance, maybe
get Excel to do more, use Excel functionality from within VBA, etc.

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



wrote in message
ups.com...
Hi there,

I've read quite a few of the "How do I speed up my VBA" posts, and
they've contained a few useful tips that I'll be using... a more
specific question...

I'm working on a monte carlo simulator whose functionality is written
pretty much entirely in a single loooong method. I've knocked a couple
of hours of it's runngin time already, and am at the point of
clutching at straws to get rid of a few more minutes...

I heard from someone that splitting my code up and approaching it from
a more OO perspective, using excel user defined classes might speed it
up. Has anyone got an opinion on this?

Any other ideas, beyond disabling screen updating would be greatfully
recieved :)

Cheers

Chris



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel VBA Class Objects - Parent & Successor Objects [email protected] Excel Programming 1 January 15th 07 12:06 AM
A class with two objects? [email protected] Excel Programming 7 June 29th 06 02:34 AM
Implementing Binary Comparisions for a class objects Robert Mulroney[_3_] Excel Programming 7 November 27th 05 10:56 PM
VBA & XL2K: Working with objects/class modules Mike Mertes Excel Programming 0 November 1st 04 02:55 PM
new class w/ graphic objects Tony Rizzo Excel Programming 1 June 7th 04 02:18 PM


All times are GMT +1. The time now is 05:18 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"