Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Timing

Timing
Thread Tools
Senior User
Join Date: Nov 2000
Status: Offline
Reply With Quote
Jun 6, 2001, 01:46 PM
 
What's the easiest way to time a method? It doesn't have to be really precise. I just need to compare two methods that do the same thing to see which is faster.

Code would be much appreciated.

TIA!
     
ali
Forum Regular
Join Date: Sep 2000
Status: Offline
Reply With Quote
Jun 6, 2001, 03:34 PM
 
You said "method," so I'm assuming you're using ObjC and Cocoa. You can use NSDate easily:

<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>NSTimeInterval t = [NSDate timeIntervalSinceReferenceDate];

<font color = brown>/* <font color = green>do</font> whatever you want to <font color = green>do</font> */</font>

t = [NSDate timeIntervalSinceReferenceDate] - t;

<font color = brown>/* So now t holds the elapsed time in seconds (as a <font color = green>double</font>) */</font>
</font>[/code]

If you are not using Cocoa, CFDate (in CoreFoundation) also has similar functionality.

Ali
     
IamBob  (op)
Senior User
Join Date: Nov 2000
Status: Offline
Reply With Quote
Jun 6, 2001, 05:57 PM
 
Yeah, your assumption was correct. I suppose "method" could've meant I was using Java though.

Thanks.
     
Junior Member
Join Date: Mar 2001
Status: Offline
Reply With Quote
Jun 7, 2001, 07:01 PM
 
The Sampler application included with the developer tools is a good way to benchmark methods and especially to find bottlenecks in your app. This page shows you how to use it.
http://www.mulle-kybernetik.com/opti-1.html

-Peter
     
IamBob  (op)
Senior User
Join Date: Nov 2000
Status: Offline
Reply With Quote
Jun 7, 2001, 09:06 PM
 
Yeah, Sampler may come in handy some time. I tinkered with it in the Public Beta. Thanks for the link.

I still like hand timing my stuff though. I just had to methods that did the same thing and wanted to see which was faster. Turned out that one method was about 45% faster when working on small sets and the other was about 30% faster when working on large sets.

So..
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
<font color = green>if</font> (set is huge) [<font color = purple>self</font> useFastForHuge:set];
<font color = green>else</font>
[<font color = purple>self</font> useFastForSmall:set];
</font>[/code]
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:48 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2