R
Roy Gourgi
Hi,
How much is C# slower than C++?
TIA
Roy
How much is C# slower than C++?
TIA
Roy
Roy Gourgi said:Hi,
How much is C# slower than C++?
Michael said:Depends on what you're doing. There no inherent reason for it to be slower
at all. MSIL is compiled into native machine code before it executes.
jeremiah johnson said:That compilation takes place with a JIT (Just In Time) compiler, and this
adds time to the execution. It is noticeably slower.
jeremiah johnson said:That compilation takes place with a JIT (Just In Time) compiler, and
this adds time to the execution. It is noticeably slower.
How much slower though, depends on what you're doing. Some argue half
as fast, some argue 1/4 as fast.
Scott said:As a "débutant" in c++, I did the following in c# and in c++, just to see
for myself:
namespace PerfTest
{
struct Obj {
public int a,b,c,d,e,f,g,h,i,j, k, l, m,n,o,p,q,r,s,t,u,v,w,x,y,z;
int get_i() { return i;}
}
class Class1
{
static void pass_by_value(Obj o) {
o.i++;
}
static void pass_by_ref(ref Obj o) {
o.i++;
}
[STAThread]
static void Main(string[] args)
{
Obj obj = new Obj();
DateTime start, finish;
TimeSpan duration;
Console.WriteLine("CSHARP test.");
Console.Write("How many? ");
int count = Convert.ToInt32(Console.ReadLine());
Console.Write("Test pass by value: ");
start = DateTime.Now;
for(int i=0; i<count; i++)
pass_by_value(obj);
finish = DateTime.Now;
duration = finish - start;
Console.WriteLine("{0} ms.", duration.Milliseconds);
Console.Write("Test pass by ref : ");
start = DateTime.Now;
for(int i=0; i<count; i++)
pass_by_ref(ref obj);
finish = DateTime.Now;
duration = finish - start;
Console.WriteLine("{0} ms.", duration.Milliseconds);
Console.Write("[Enter] to quit."); Console.ReadLine();
}
}
}
c# turned out to be 10x faster over 10e6 loops, but I suspect it was
because JIT (or whatever) optimized away a lot of the work I was trying to
make the computer do. I'm not saying c# is faster most of the time, but
in my little test, it was. Of course, startup time for c# apps is longer
than for c++ for the reasons mentioned elsewhere in this thread.
scott
Roy Gourgi said:Hi,
How much is C# slower than C++?
TIA
Roy
Scott Coonce said:just in case anybody comes along and reads this thread again, i made the
classic mistake of comparing the "debug" builds. so as i've read in other
threads, all timing comparison bets are off.
scott
Scott said:As a "débutant" in c++, I did the following in c# and in c++, just to see
for myself:
namespace PerfTest
{
struct Obj {
public int a,b,c,d,e,f,g,h,i,j, k, l, m,n,o,p,q,r,s,t,u,v,w,x,y,z;
int get_i() { return i;}
}
class Class1
{
static void pass_by_value(Obj o) {
o.i++;
}
static void pass_by_ref(ref Obj o) {
o.i++;
}
[STAThread]
static void Main(string[] args)
{
Obj obj = new Obj();
DateTime start, finish;
TimeSpan duration;
Console.WriteLine("CSHARP test.");
Console.Write("How many? ");
int count = Convert.ToInt32(Console.ReadLine());
Console.Write("Test pass by value: ");
start = DateTime.Now;
for(int i=0; i<count; i++)
pass_by_value(obj);
finish = DateTime.Now;
duration = finish - start;
Console.WriteLine("{0} ms.", duration.Milliseconds);
Console.Write("Test pass by ref : ");
start = DateTime.Now;
for(int i=0; i<count; i++)
pass_by_ref(ref obj);
finish = DateTime.Now;
duration = finish - start;
Console.WriteLine("{0} ms.", duration.Milliseconds);
Console.Write("[Enter] to quit."); Console.ReadLine();
}
}
}
c# turned out to be 10x faster over 10e6 loops, but I suspect it was
because JIT (or whatever) optimized away a lot of the work I was trying to
make the computer do. I'm not saying c# is faster most of the time, but
in my little test, it was. Of course, startup time for c# apps is longer
than for c++ for the reasons mentioned elsewhere in this thread.
scott
Roy Gourgi said:Hi,
How much is C# slower than C++?
TIA
Roy
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.