Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

comparing algorithm performance
tofutim
#1 Posted : Saturday, January 25, 2014 5:07:25 AM(UTC)
Rank: Member

Groups: Registered
Joined: 8/27/2012(UTC)
Posts: 19
Location: California

Thanks: 2 times
Was thanked: 2 time(s) in 2 post(s)
Is it possible to use NCrunch to compare algorithm performance in terms of timing or memory?
Remco
#2 Posted : Saturday, January 25, 2014 5:43:27 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,982

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
To a limited extent, yes.

NCrunch's built-in performance analysis does allow algorithms to be inspected line-by-line for their performance. In theory, if you wrote two tests running two different algorithms, the code coverage should report bottlenecks and the test execution times could give you a ballpark on the speed of the algorithms and how they compare.

Where this starts to fall down is that NCrunch is restricted to running code only in debug mode (i.e. not release mode). This means that where algorithms make use of compiler optimisations, the performance analysis will not be as accurate. The instrumentation used for the analysis is also quite heavy for frequently executed code and this will likely distort the metrics, as algorithms that execute more lines of code will be significantly worse off than others.

So I would have to say that NCrunch is useful for evaluation the performance of algorithms and discovering their bottlenecks, but I would recommend against using it for making important decisions or publishing comparisons without taking account of the above limitations.

At the moment, NCrunch doesn't have any features that measure memory allocation or resource efficiency. In this area, it probably isn't more useful than any other test runner.

I hope this helps!


Cheers,

Remco
1 user thanked Remco for this useful post.
tofutim on 1/25/2014(UTC)
tofutim
#3 Posted : Saturday, January 25, 2014 5:33:42 PM(UTC)
Rank: Member

Groups: Registered
Joined: 8/27/2012(UTC)
Posts: 19
Location: California

Thanks: 2 times
Was thanked: 2 time(s) in 2 post(s)
Is there any quick way of exporting timings to compare against future timings?
Remco
#4 Posted : Sunday, January 26, 2014 12:05:07 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,982

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
Not within NCrunch. Something you could try is to wrap the test itself inside a timer, then dump the results to a log file. For example:

[Test]
public void ExecuteAlgorithmWithPerformanceMeasurement()
{
var stopWatch = Stopwatch.StartNew();
stopWatch.Stop();

var algorithm = new Algorithm();
algorithm.Execute();

using (var logFile = new StreamWriter(@"C:\Temp\MyAlgorithmTestTimings.log", true))
logFile.WriteLine(DateTime.Now + ": Algorithm took " + stopWatch.Elapsed + " to execute");
}
tofutim
#5 Posted : Tuesday, January 28, 2014 12:41:09 AM(UTC)
Rank: Member

Groups: Registered
Joined: 8/27/2012(UTC)
Posts: 19
Location: California

Thanks: 2 times
Was thanked: 2 time(s) in 2 post(s)
Can you enable Copy out of the Datagrid so I can paste the timings into Excel?

Remco
#6 Posted : Tuesday, January 28, 2014 2:16:52 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,982

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
There are plans to introduce an export feature to export the contents of the Tests Window. Would this also work for you?
tofutim
#7 Posted : Tuesday, January 28, 2014 2:26:43 AM(UTC)
Rank: Member

Groups: Registered
Joined: 8/27/2012(UTC)
Posts: 19
Location: California

Thanks: 2 times
Was thanked: 2 time(s) in 2 post(s)
That work too - but cut and paste out of the test window would let me add more columns into a preexisting xls
1 user thanked tofutim for this useful post.
Remco on 1/28/2014(UTC)
tofutim
#8 Posted : Wednesday, January 29, 2014 6:32:18 PM(UTC)
Rank: Member

Groups: Registered
Joined: 8/27/2012(UTC)
Posts: 19
Location: California

Thanks: 2 times
Was thanked: 2 time(s) in 2 post(s)
For the timing, I wonder if it is possible to get CPU time - amount of cpu cycles - instead of processing time.
Remco
#9 Posted : Wednesday, January 29, 2014 9:54:17 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,982

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
Sorry, you'd need to trace this manually with something like perfmon. NCrunch just isn't designed to capture CPU cycles.
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.049 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download