I'm Shocked! Is C# really slower than php?

Eloff

Freshman
Joined
Mar 20, 2003
Messages
35
Location
Canada
Ok this can't be possible, maybe I'm messing up something here.

private System.DateTime startTime = System.DateTime.Now;
/*script below with a oledb connect to mysql, a single (tiny) insert query, a file open, read a single line, and close, and 30 milliseconds worth of text parsing.*/
Console.WriteLine(System.DateTime.Now.Subtract(startTime).TotalSeconds);

This spits back 1 second when run on my 1.8Ghz machine.

A 1,400 line php program, with tons of text manipulation, including regular expressions, several loops, and about a hundred if statements and over 20 mysql queries runs in a third of the time.

Why is the C# program so slow? Did I just make a very big mistake deciding to rewrite my php program in C# to increase the speed?
 

/*script below with a oledb connect to mysql, a single (tiny) insert query, a file open, read a single line, and close, and 30 milliseconds worth of text parsing.*/


A 1,400 line php program, with tons of text manipulation, including regular expressions, several loops, and about a hundred if statements and over 20 mysql queries runs in a third of the time.

Sounds to me you're doing different things with the individual languages. So how can you accurately benchmark them vs each other?

A few things on your C# compared to PHP..
-Did you use buffered streams for file processing in C#, and did you use any file processing at all in PHP?
-Did you use regular expressions in your text parsing for C# like you did with PHP?
-What was the code you used to determine the seconds with PHP?
-Did you run several tests and not just one? Every .NET program is always slow the FIRST time it's run as it has to be compiled.
-Did you consider that .NET just may be slower with MySQL compared to PHP as PHP was built from the ground up to use it, while in .NET you're using OleDb which are generic drivers? .NET is intended to work with MS SQL Server (or MSDE if that's what you got) from my understanding.
 
Yes, it's the mysql, without that it runs at 70ms, vs 1000ms. I'm going to stick to my php:) I did do many tests, the compile time shouldn't have affected anything because the code in the actually c# program was used for the benchmark, and it only starts executing after the compile if I'm not mistaken. No regualr expressions in the c#, and with nothing but the database connect and query it runs at a speedy 950ms :( Pitiful really. Even the 70ms for the text processing and file reading was pitiful. And a completely blank c# program took 40ms to execute (just the benchmark in it) which baffles me. I think php with the accelerator that caches a compiled version is a way better option, especially when working with mysql.
 
No regualr expressions in the c#

It sounds like you're using PHP efficiently but just hacked out a random C# program for comparison. How can you accurately benchmark something when doing this.. :confused:

Maybe you should .zip up your "test" C# code and let some of the board gurus look at it and see if there's any way to make it more efficient.
 
Back
Top