473,769 Members | 3,305 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Bizarre benchmark result -- C# hundreds of times slower than Java?

While asking some Java enthusiasts what they think about C#, I came across
this:

http://www.manageability.org/blog/ar...m_with_cameron

Reportedly, the (essentially) same program in C# is much, much slower than
in Java.

This is a program that is heavy on regexes (which I'm not an expert on) and
am wondering if the C# version makes an elementary blunder. Do any experts
want to have a look? See also comp.lang.java.

(Query: Is he compiling the regex once in Java, but every time through the
loop in C#?)


Mar 11 '08 #1
4 2040
This is a program that is heavy on regexes (which I'm not an expert on) and
am wondering if the C# version makes an elementary blunder. *Do any experts
want to have a look? *See also comp.lang.java.

(Query: Is he compiling the regex once in Java, but every time through the
loop in C#?)
I think he is compiling the regular expression each time in the loop.
A good benchmark would be compiling it once and matching it in the
loop. Maybe C# uses a DFA-NFA hybrid (which might explain the large
memory usage, as the author of the article claims) which has the
potential of matching a regular expression several times faster than a
backtracking implementation, but it would compile the regular
expression slower than backtracking.

Another good benchmark would include the use of backreferences, which
forces a regex implementation to use backtracking.

FYI, egrep uses a DFA-NFA hybrid.
Mar 13 '08 #2
Thanks for the links! Very helpful and interesting.
Ethan
Plenty, usually caused by the fact that regexes aren't regular expressions
(the theoretical constructs, which always match in linear time). See, e.g.,
http://www.codinghorror.com/blog/archives/000488.html and
http://www.regular-expressions.info/catastrophic.html.
Mar 13 '08 #3
I don't want to be the one making Jesus cry, but I am not sure that my code
is what is doing it. I see that representing DNA as strings is not going to
make the cpu as happy as it could be, but it is not obvious to me how to
represent DNA (and RNA and protein, so I can't use a byte array anymore) as a
numeric array and still get relatively programmer friendly functionality.
I started yesterday (code below...) and stopped pretty rapidly because I
don't see a way to recreate IndexOf or Regex type functionality without a lot
of work! If you have anything more complete I would be interested!
Thanks,
Ethan

using System;
using System.Collecti ons.Generic;
using System.Text;

namespace TestSequence
{
public struct DNA
{
private DNABase[] _Sequence;
public DNA(string sequence)
{
List<DNABaseThi sSequence = new List<DNABase>() ;
foreach (char thisBase in sequence.ToUppe r().ToCharArray ())
{
DNABase NextBase;
switch (thisBase)
{
case "G":
{
NextBase = DNABase.G;
break;
}
case "A":
{
NextBase = DNABase.A;
break;
}
case "T":
{
NextBase = DNABase.T;
break;
}
case "C":
{
NextBase = DNABase.C;
break;
}
default:
{
continue;
}
}
ThisSequence.Ad d(NextBase);
}
_Sequence = ThisSequence.To Array();
}
}
public enum DNABase : byte
{
N = 0,
G = 1,
A = 2,
T = 3,
C = 4
}
}
And I hope you realise that using strings to represent DNA sequences
except for input/output makes baby Jesus cry. Your programs would be
faster and more maintainable using your own type (probably backed by a
byte[] and some unsafe code). The best way to represent it normally
depends on what you're doing and whether you need to consider SNPs, but
Unicode strings are a bad idea!

Alun Harford
Mar 13 '08 #4
Hello Michael,
While asking some Java enthusiasts what they think about C#, I came
across this:

http://www.manageability.org/blog/ar...he_problem_wit
h_cameron

Reportedly, the (essentially) same program in C# is much, much slower
than in Java.

This is a program that is heavy on regexes (which I'm not an expert
on) and am wondering if the C# version makes an elementary blunder.
Do any experts want to have a look? See also comp.lang.java.

(Query: Is he compiling the regex once in Java, but every time through
the loop in C#?)
Replacing
Regex regexpr = new Regex(matchthis , RegexOptions.Co mpiled);

with
Regex regexpr = new Regex(matchthis , RegexOptions.No ne);

made it fly.

--
Jesse Houwing
jesse.houwing at sogeti.nl
Mar 14 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1922
by: engsolnom | last post by:
Knowing absolutely zero about benchmarks, I was interested in the posting referencing the paper by Dr. Cowell-Shah. I was curious how long Python takes just to read and display time.clock(), soI made the simple test below. I was amazed at the difference in speed depending on when/how the clock times were converted to milliseconds....almost 4 to 1...as indicated in the RESULTS below. I understand the variation in the times is probably due...
3
3006
by: Steve | last post by:
Hi, I'm currently looking a porting our Windows Codewarrior based C++ projects to MinGW and/or Visual Studio and I'm just wondering if there is a 'standard' suite of benchmark programs I can download and compile on the various environments that will give me an idea on the relative performance of each STL? For example - a test program that will run through, say, appending one character to a string 1000000 times, copying vectors,...
7
1873
by: Ralph Mason | last post by:
I was looking at this page http://www.garret.ru/~knizhnik/dybase/doc/dybase.html And noticed running the same code (Java ported to C# using the MS tool I expect) that the C# implementation is over 50% slower than Java in all tests. Coming in at the same speed as Ruby, which isn't known for it's speed, but is totally dynamic and interpreted. Something doesn't seem quite right.
87
4988
by: John Rivers | last post by:
Hello everybody, I just wondered if anybody else has noticed this? It takes around 6 seconds to start debugging a very simple ASPX page with VS.NET whereas VB6 takes under 0.5 seconds, even with very large and complex projects. This is a real shame :(
74
4606
by: aruna.mysore | last post by:
Hi all, I have a simple definitioin in a C file something like this. main() { char a; ....... int k; }
29
5512
by: wizofaus | last post by:
I previously posted about a problem where it seemed that changing the case of the word "BY" in a SELECT query was causing it to run much much faster. Now I've hit the same thing again, where basically almost any change I make to how the query is executed (so that it still performs the same function) causes the performance to jump from a dismal 7 or 8 seconds to instantaneous. It's a very simple query of the form: SELECT Min(MyValue)...
16
2725
by: Jorge | last post by:
Webkit r34469 vs. Opera 9.50 : 3.00x as fast 6339.6ms(Opera) 2109.8ms (Webkit) ----- FF3.0 (final) vs. Opera 9.50 : 1.94x as fast 6339.6ms (Opera) 3269.6ms (FF3)
0
1276
by: Jon Harrop | last post by:
A JVM developer called John Rose from Sun Microsystems recently claimed on a mailing list that Sun's JVM offers C-like performance whereas .NET only offers performance comparable to old JVM implementations: http://groups.google.com/group/jvm-languages/msg/e8ee4b7f74c93ded I thought I'd test this by running the Java and C# implementations of the commonly-cited SciMark benchmark. At first sight, Sun's JDK 6 was 5% faster than .NET 3.5.
37
2038
by: Jack | last post by:
I know one benchmark doesn't mean much but it's still disappointing to see Python as one of the slowest languages in the test: http://blog.dhananjaynene.com/2008/07/performance-comparison-c-java-python-ruby-jython-jruby-groovy/
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10216
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10049
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9997
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3965
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3565
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.