.NET

Reply
Distinguished Contributor
195 Posts
0 Kudos
Registered: ‎04-02-2005
Post 1 of 3

A performance question

81 Views, 2 Replies
12-08-2005 09:33 PM
Don’t mean to waste news group space. But why is c# roughly 5 times faster than C++ running the same code. I certainly thought it would be the other way around.

//c# .net 2.0
int Fibonacci(int n)
{
if (n == 0 || n == 1)
return n;
else
return Fibonacci(n - 1) + Fibonacci(n - 2);
}


//c++ VC++7 standard
long Fibonacci(int n)
{
if (n == 0 || n == 1)
return n;
else
return Fibonacci(n - 1) + Fibonacci(n - 2);
}
*Adam Nagy
Post 2 of 3

Re: A performance question

12-09-2005 05:19 AM in reply to: dmarcotte4
Hello Danielm,

Try out both in release mode...

Cheers,
Adam
> Don't mean to waste news group space. But why is c# roughly 5 times
> faster than C++ running the same code. I certainly thought it would
> be the
> other way around.
> //c# .net 2.0
> int Fibonacci(int n)
> {
> if (n == 0 || n == 1)
> return n;
> else
> return Fibonacci(n - 1) + Fibonacci(n - 2);
> }
> //c++ VC++7 standard
> long Fibonacci(int n)
> {
> if (n == 0 || n == 1)
> return n;
> else
> return Fibonacci(n - 1) + Fibonacci(n - 2);
> }
Distinguished Contributor
195 Posts
0 Kudos
Registered: ‎04-02-2005
Post 3 of 3

Re: A performance question

12-09-2005 02:10 PM in reply to: dmarcotte4
Hey Adam,
That was it, they were compiled in debug mode. Thanks a ton.

Daniel
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!