Dear Sir/Madam,

I have two types of procedure for one/same result. No. 1 procedure is very long without loop and no. 2 procedure is sort with many loops. So I want to check those procedure, which one is taking less time than another.

Please guide me.

Execution time is independent of lines of code.
It may happen that a procedure has 1000 lines of code because of a long running IF ELSE but the line 10 to 1000 never gets executed.

It depends on what the code is actually doing.

Execution time is independent of lines of code.
It may happen that a procedure has 1000 lines of code because of a long running IF ELSE but the line 10 to 1000 never gets executed.

It depends on what the code is actually doing.

Thanks for replying, but i need the method or technique how to check the time required for those procedure.

Add a timer 1 and 2 to your form. In your loop add a time factor to a label, something like -

'Your loop started...
Label1.Caption = Label1.Caption + Timer1.Interval
Timer1.Enabled = False
Timer1.Enabled = True

Simply print system time at the beginning of the Procedure (before any looping or conditional branching) and once again at the end . and check the difference.

Dear AndreRet,

Thanks for your reply. I have tried with timer earlier also but that was not worked. Anyway thanks for your reply.

Dear Debasisdas,

Thanks for your simple but excellent logic which has worked for me. And for your kind information both the procedure has taken same time.

Thank you all

As i have said earlier , that would depend on what the procedure is doing.

for example if your procedure is doing some data processing test it against Hugh data, definitely you will get some difference in execution time.

I agree with Das, hence my first suggestion with timers where you can get an interval of 0.001 seconds. a Normal 1 record data retrieval normally returns within 0.009 seconds depending on your system, network, database etc, which by using the system time will show as the same time for both tests. If comparing huge databases, it might work, but you still will not get a 100% returned value.:)

My 2 cents worth.:)

Dear AndreRed,

I have a program to make a Calendar on Excel Sheet. Where Calendar year will be chosen by user and giving his own/office holiday list.

On that program the main procedure is taking few time for fully executing. I have tried as Dbasisdas said and after that i have got, the procedure is taking 1 to 10 seconds. Execution time is very machine to machine. And it's OK.

As you have pointed out, i am bound to agree with you, though i have got the result by using system time. Problem is that i am not getting the result using timer. I have tried like this........

1st one ----------------
Private Sub Form_Load()
Timer1.Interval = 100
Timer1.Enabled = False
End Sub

Private Sub Timer1_Timer()
Label1.Caption = Val(Label1.Caption) + 1 '1 is equal to 0.1 second
End Sub

Private Sub Command1_Click()
Timer1.Enabled = True
'my all codes here
Timer1.Enabled = False
End Sub

here timer1 is not working or label1's caption(number) not increasing


2nd one --------------------
Dim cnt As Integer
Dim TM1 As Integer

Private Sub Form_Load()
cnt = 0
TM1 = 0
Timer1.Interval = 100
Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
cnt = cnt + 1
End Sub

Private Sub Command1_Click()
cnt = 0
'my all codes here
TM1 = cnt
Label1.Caption = TM1
End Sub

Here also timer1 become pause at the time of running command1 procedure.

If any other different techniques or coding is require please guide. I want to use timer also.

This has already been marked as solved. Please open a new thread with your above question and the code, I have already converted the code which counts up to 0.001 of a second, which will give you a true indication.

Also post your loop in the new post, the timer actions will be contained there in. I will post a solution as soon as you have opened the new thread.:)

Also send me a PM that the new post is open, otherwise I might miss it whilst working.:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.