Link to home
Start Free TrialLog in
Avatar of vairavamuthu
vairavamuthu

asked on

i want to know whether ordinery function slows down a appplication

Hi experts,
 my question is that iam having a lot of function in my form to reduce complexity and have genral flexibility i placed them in modules.. the think i want to know is does this function  really help in speeding upof a application as it is reducing complexity code wise.... so i want to know having more function is help ful or not

2.. i like have some sample codes for function passing mutilple parameters and returning multiple parameters

looking for  a solution


regards
vairavamuthu
ASKER CERTIFIED SOLUTION
Avatar of sgayatri
sgayatri

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JohnBPrice
JohnBPrice

Functions reduce complexity, but slightly slows down your application.

VB is not the fastest language in the world, and if your app is performance critical, VB is not a great choice, but if your application is otherwise fine, but you have one bit that is too slow, you might be able to speed it up.  For example, look at this code, a simple loop doing simple math, one way in a function, the other with inline code.  The function loop takes about 16 seconds on my machine, the inline loop takes 2 seconds.  e.g. each function call takes about 0.00000056 seconds.  Not much, but it adds up if you are doing 25,000,000 calls.

Option Explicit

Private Sub CmdWithFunction_Click()
    Dim starttime As Date
    Dim stoptime As Date
    Dim i As Integer, j As Integer
    Dim result As Long
    Screen.MousePointer = vbHourglass
    starttime = Time
        For i = 1 To 5000
            For j = 1 To 5000
                result = MyFunction(i, j)
            Next j
        Next i
    stoptime = Time
    Screen.MousePointer = vbDefault
    MsgBox DateDiff("s", starttime, stoptime)
End Sub

Function MyFunction(i As Integer, j As Integer) As Long
    MyFunction = i + j
End Function

Private Sub CmdNoFunction_Click()
    Dim starttime As Date
    Dim stoptime As Date
    Dim i As Integer, j As Integer
    Dim result As Long
    Screen.MousePointer = vbHourglass
    starttime = Time
        For i = 1 To 5000
            For j = 1 To 5000
                result = i + j
            Next j
        Next i
    stoptime = Time
    Screen.MousePointer = vbDefault
    MsgBox DateDiff("s", starttime, stoptime)

End Sub