?
Solved

vb.net - see how long it took

Posted on 2009-12-18
9
Medium Priority
?
256 Views
Last Modified: 2012-05-08
hello there,
I have a little function that searches for a name inside a text file but it finds it so fast that I cant not even know how long it took.. so right now I have a different function but I would like to know which one finds the name faster.. so my question is what can I do to know which one finds it faster?
0
Comment
Question by:XK8ER
  • 4
  • 3
  • 2
9 Comments
 
LVL 10

Accepted Solution

by:
joriszwaenepoel earned 100 total points
ID: 26081940
dim start as datetime = datetime.Now

' do the work here

dim duration as TimeSpan = DateTime.Now.Subtract(start)
MsgBox(duration.TotelMilliseconds.ToString())
0
 
LVL 86

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 100 total points
ID: 26082033
You can also use a StopWatch:
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim sw As New Stopwatch
        sw.Start()
        foo()
        sw.Stop()
        MessageBox.Show("Total Milliseconds: " & sw.ElapsedMilliseconds)
    End Sub

    Private Sub foo()
        ' ...operation foo...
    End Sub

End Class

Open in new window

0
 
LVL 1

Author Comment

by:XK8ER
ID: 26082055
the last line shows this

Error      1      'TotelMilliseconds' is not a member of 'System.TimeSpan'.      
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 26082067
He just spelled it wrong...

"TotelMilliseconds" should be "TotalMilliseconds"
0
 
LVL 10

Expert Comment

by:joriszwaenepoel
ID: 26082072
Make that "TotalMilliseconds" ... sorry about that, but I wrote the code in the browser.
0
 
LVL 1

Author Comment

by:XK8ER
ID: 26082083
Idle_Mind, you code works.. how come I always get a different number even though its the same file and same string to search?
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 26082118
Uh...we're dealing in MILLISECONDS here so I would expect to see some differences since it's dealing with physical media.  The heads on th e drive have to physically move around, etc.  Also, the system can be doing other things affecting the time taken.

How much difference are you seeing?  

Be a ~little~ more scientific bud.  Run a series of tests and average the results.  Compare the average time of your different approaches.  =)
0
 
LVL 1

Author Comment

by:XK8ER
ID: 26082139
both codes work wonderful.. here's what im getting

1704
1941
1904
1865
1847
1869
1892
1869
1905
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 26082300
Also be aware that the data from the file might get cached after the first read and subsequent reads will be super fast in comparison to the first...just depends on how small the file is and how much memory is available at the time of execution, etc...
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question