C# Performance Problem

B

badrbadr

Hi,
Today, I find a problem from an old Google Code Jam Contest.
You can read the problem statement here :
http://www3.sympatico.ca/red.zrari/problem.htm

I solved the problem in 15 min (wow, c# is very productive but...) but
my program takes a long time (1 min 15 sec) to solve the example 5 (see
the problem statement).
I found a C++ program that uses the same method than my program.
However, this program is a lot faster : it solves the example 5
in...0sec.

I can't understand why my C# program takes more than 1 minutes since
they use the same method.

The link to my C# program source code :
http://www3.sympatico.ca/red.zrari/csharp.htm
The link to the C++ program source code :
http://www3.sympatico.ca/red.zrari/c++.htm

Man, it's really embarrassing -_-
Hope it's my fault and not the .net framework fault.

My PC Configuration:
- AMD Athlon XP 2800+
- Windows XP Pro SP2
- .Net framework 2.0
- Visual C# Express 2005 and Visual C++ Expresss 2005
 
C

chanmm

The code are somehow different C++ using STL and pointer "vector<point> &vp"
for example. So you should look at the generic class in C# too.

chanmm
 
B

Bill Butler

badrbadr said:
Hi,
Today, I find a problem from an old Google Code Jam Contest.
You can read the problem statement here :
http://www3.sympatico.ca/red.zrari/problem.htm

I solved the problem in 15 min (wow, c# is very productive but...) but
my program takes a long time (1 min 15 sec) to solve the example 5
(see
the problem statement).
I found a C++ program that uses the same method than my program.
However, this program is a lot faster : it solves the example 5
in...0sec.

I can't understand why my C# program takes more than 1 minutes since
they use the same method.

The link to my C# program source code :
http://www3.sympatico.ca/red.zrari/csharp.htm
The link to the C++ program source code :
http://www3.sympatico.ca/red.zrari/c++.htm

Man, it's really embarrassing -_-
Hope it's my fault and not the .net framework fault.

I suggest that you verify that both versions are actually answering the
same question (they're not). Take a close look at your short circuit
execution in both cases (that is where you return -1). Next, take a look
at your bounds on the C++ version.
I don't understand why the C++ version look so different from the C#
version. There is no reason that you couldn't get them much more similar
in behavior. For instance, you don't even declare a class in the C++
version. If you wish to get a realistic comparison between languages,
you really need to make sure that both programs are doing the SAME
thing.

Good luck,
Bill
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top