benchmarks? java vs .net

1 view
Skip to first unread message

King Raz

unread,
May 30, 2008, 11:28:07 PM5/30/08
to
The shootout site has benchmarks comparing different languages. It
includes C# Mono vs Java but not C# .NET vs Java. So I went through
all the benchmark on the site ...

http://kingrazi.blogspot.com/2008/05/shootout-c-net-vs-java-benchmarks.html

Just to keep the post on topic for my friends at comp.lang.c++, how do
I play default windows sounds with C++?

Andrea Francia

unread,
May 31, 2008, 2:09:12 PM5/31/08
to

This guy had trolled the comp.lang.java.programmer and comp.lang.c++
newsgroup for many weeks with pretentious post about the performance
comparison of C++ and Java.
The comparison was done in a not scientific way with only purpose of get
replies.
To get replies he/she send many replies to each message he/she receives.

For reach is target he/she changed his/hers email address many times to
avoid killfiles.

I suggest the people not interested who have thunderbird to install the
"Right click ingore/watch thread" extension and use it for ignoring this
thread.

--
Andrea Francia
http://andreafrancia.blogspot.com/

Razii

unread,
May 31, 2008, 3:24:10 PM5/31/08
to
On Sat, 31 May 2008 18:09:12 GMT, Andrea Francia
<andrea....@REMOVE-FROM-HERE.ohoihihoihoih.TO-HERE.gmx.it> wrote:

>This guy had trolled the comp.lang.java.programmer and comp.lang.c++
>newsgroup for many weeks with pretentious post about the performance
>comparison of C++ and Java.

This got to be the funniest post. She (or is that he?) cross-posts
(spams?) three newsgroups with the subject "Please don't feed the
troll" and this post was the only response to my thread. Thanks for
feeding me. She/He also quotes my entire post so anyone who missed my
first post now read it :) Now I know at least one person read my
post; that is the brilliant: Andrea Francia, for Italy :)

Were you born this stupid or did someone hit you with a baseball bal?

Razii

unread,
May 31, 2008, 8:40:20 PM5/31/08
to
On Sat, 31 May 2008 14:24:10 -0500, Razii <fg...@mail.com> wrote:

>This got to be the funniest post. She (or is that he?) cross-posts
>(spams?) three newsgroups with the subject "Please don't feed the
>troll" and this post was the only response to my thread. Thanks for
>feeding me. She/He also quotes my entire post so anyone who missed my
>first post now read it :) Now I know at least one person read my
>post; that is the brilliant: Andrea Francia, for Italy :)

Arrrgh. I meant "from Italy"

In any case, if you think I am a troll, why would you feed me by
responding to my post? Why would you quote my entire post, advertising
it for free? People who missed the first post now must have read my
post, thanks to Andrea Francia.

Well, it seems, the programming-related newsgroups have some of
the dumbest people on USENET. I wonder why?

Jeff Higgins

unread,
May 31, 2008, 8:45:57 PM5/31/08
to

Andrea Francia wrote:

> I suggest...

!Thanks for the respam. I'd have never been aware of this
post had it not been for your announcement and sage advice.

I'm sure k.rzi thanks you for reposting a link to his site.


Jon Harrop

unread,
Jun 2, 2008, 5:22:29 AM6/2/08
to

Yes. I have ported a variety of benchmarks and found there is no significant
difference between the performance of .NET and Java. The one result that
stood out was .NET being 2x faster at the Mersenne Twister PRNG.

--
Dr Jon D Harrop, Flying Frog Consultancy
http://www.ffconsultancy.com/products/?u

Razii

unread,
Jun 2, 2008, 4:56:24 PM6/2/08
to
On Mon, 02 Jun 2008 10:22:29 +0100, Jon Harrop <j...@ffconsultancy.com>
wrote:

>Yes. I have ported a variety of benchmarks and found there is no significant
>difference between the performance of .NET and Java. The one result that
>stood out was .NET being 2x faster at the Mersenne Twister PRNG.

.NET is twice slower in four benchmarks: binarytrees, mandelbrot,
regexdna, sumcol. .NET was twice faster only in trig related
benchmark.

Razii

unread,
Jun 2, 2008, 5:33:40 PM6/2/08
to
On Mon, 02 Jun 2008 10:22:29 +0100, Jon Harrop <j...@ffconsultancy.com>
wrote:

>Yes. I have ported a variety of benchmarks and found there is no significant


>difference between the performance of .NET and Java. The one result that
>stood out was .NET being 2x faster at the Mersenne Twister PRNG.

.NET is twice slower in four benchmarks: binarytrees, mandelbrot,

Jon Harrop

unread,
Jun 2, 2008, 8:23:00 PM6/2/08
to

You have not optimized the .NET code:

On the mandelbrot benchmark, most of the time is spent doing unbuffered IO.
Use buffered IO and .NET becomes ~10% faster than Java.

On the regexdna benchmark, the regular expressions are not being compiled.
Ask for compilation and the .NET is <20% slower than Java.

The sumcol benchmark is also using unbuffered IO.

So neither VM is significantly faster overall.

Razii

unread,
Jun 2, 2008, 9:21:04 PM6/2/08
to
On Tue, 03 Jun 2008 01:23:00 +0100, Jon Harrop <j...@ffconsultancy.com>
wrote:

>On the mandelbrot benchmark, most of the time is spent doing unbuffered IO.


>Use buffered IO and .NET becomes ~10% faster than Java.

The output was directed to /NULL so I don't see how buffering makes
the difference. In any case, post the version that makes it 10%
faster. Right now it's 2 times slower.

>On the regexdna benchmark, the regular expressions are not being compiled.
>Ask for compilation and the .NET is <20% slower than Java.

The version that compiles regex is slower that then the version that
doesn't compile on Mono

http://shootout.alioth.debian.org/gp4/benchmark.php?test=regexdna&lang=all

That's because the regular expression is used only once and compiling
it makes it slower. I doubt the compiled version will be faster on
.NET. It will be slower.

>The sumcol benchmark is also using unbuffered IO.

Post the right version that buffers then.

>So neither VM is significantly faster overall.

.NET is 2 times slower in 4 of the benchmarks. Post the version that
makes it faster so we can verify. You haven't done it yet.

Razii

unread,
Jun 2, 2008, 9:35:44 PM6/2/08
to
On Mon, 02 Jun 2008 20:21:04 -0500, Razii <klgd...@mail.com> wrote:

>The version that compiles regex is slower that then the version that
>doesn't compile on Mono
>
>http://shootout.alioth.debian.org/gp4/benchmark.php?test=regexdna&lang=all

Ok, I did try compiled version on .NET and it was faster than
uncompiled version.

9.539s (uncompiled)
5.165s (compiled)

the java version was 3.956s


Razii

unread,
Jun 2, 2008, 10:03:12 PM6/2/08
to
On Tue, 03 Jun 2008 01:23:00 +0100, Jon Harrop <j...@ffconsultancy.com>
wrote:

>The sumcol benchmark is also using unbuffered IO.

I changed the line to

using (StreamReader r = new
StreamReader(Console.OpenStandardInput(8192)))

Buffereing 8192 bytes now?

It made no difference.

4.861s (unbuffered)
4.839s (buffered)

still two times slower.

Razii

unread,
Jun 2, 2008, 10:06:57 PM6/2/08
to
On Tue, 03 Jun 2008 01:23:00 +0100, Jon Harrop <j...@ffconsultancy.com>
wrote:

>On the mandelbrot benchmark, most of the time is spent doing unbuffered IO.


>Use buffered IO and .NET becomes ~10% faster than Java.

Doesn't this line mean

http://shootout.alioth.debian.org/gp4/benchmark.php?test=mandelbrot&lang=csharp&id=2

Stream s = Console.OpenStandardOutput(1024);

it's buffering already, 1024 bytes?

vs this java version

http://shootout.alioth.debian.org/gp4/benchmark.php?test=mandelbrot&lang=javaxx&id=0

it's 3.4 times slower.

Mark Thornton

unread,
Jun 3, 2008, 2:55:07 AM6/3/08
to

Rather amusing really as unintentional use of unbuffered IO is a
frequent cause of Java benchmarks running more slowly than they should.
It seems that .NET copied that characteristic as well.

Mark Thornton

Jon Harrop

unread,
Jun 3, 2008, 4:12:37 AM6/3/08
to
Mark Thornton wrote:
> Rather amusing really as unintentional use of unbuffered IO is a
> frequent cause of Java benchmarks running more slowly than they should.
> It seems that .NET copied that characteristic as well.

Yes. I've no idea why they do that. Isn't buffered IO a better default?!

Razii

unread,
Jun 3, 2008, 7:49:28 AM6/3/08
to
On Tue, 03 Jun 2008 07:55:07 +0100, Mark Thornton
<mtho...@optrak.co.uk> wrote:

>Rather amusing really as unintentional use of unbuffered IO is a
>frequent cause of Java benchmarks running more slowly than they should.
>It seems that .NET copied that characteristic as well.

Harpo was wrong though. mandelbrot is buffered

Stream s = Console.OpenStandardOutput(1024);

It's still 3.4 times slower.

Verify it yourself.

http://shootout.alioth.debian.org/gp4/benchmark.php?test=mandelbrot&lang=csharp&id=2

vs

http://shootout.alioth.debian.org/gp4/benchmark.php?test=mandelbrot&lang=javaxx&id=0


3.4 times slower.

Jon Harrop

unread,
Jun 3, 2008, 11:08:17 AM6/3/08
to
Razii wrote:
> On Tue, 03 Jun 2008 01:23:00 +0100, Jon Harrop <j...@ffconsultancy.com>
> wrote:
>>On the mandelbrot benchmark, most of the time is spent doing unbuffered
>>IO. Use buffered IO and .NET becomes ~10% faster than Java.
>
> The output was directed to /NULL so I don't see how buffering makes
> the difference. In any case, post the version that makes it 10%
> faster. Right now it's 2 times slower.

Change:

Stream s = Console.OpenStandardOutput(1024);

to:

BufferedStream s = new BufferedStream(Console.OpenStandardOutput());

and the entire program becomes 2.5x faster.

>>On the regexdna benchmark, the regular expressions are not being compiled.
>>Ask for compilation and the .NET is <20% slower than Java.
>

> Ok, I did try compiled version on .NET and it was faster than
> uncompiled version.
>
> 9.539s (uncompiled)
> 5.165s (compiled)
>
> the java version was 3.956s

Yes.

>>So neither VM is significantly faster overall.
>
> .NET is 2 times slower in 4 of the benchmarks.

Java is only 2x faster in one benchmark (binarytrees) here and that is not a
well formed benchmark. Java is still over 2x slower on both partialsums and
the Mersenne Twister.

So you cannot reasonably conclude that Java is faster.

Jon Harrop

unread,
Jun 3, 2008, 11:18:34 AM6/3/08
to
Razii wrote:
> On Tue, 03 Jun 2008 07:55:07 +0100, Mark Thornton
> <mtho...@optrak.co.uk> wrote:
>>Rather amusing really as unintentional use of unbuffered IO is a
>>frequent cause of Java benchmarks running more slowly than they should.
>>It seems that .NET copied that characteristic as well.
>
> Harpo was wrong though. mandelbrot is buffered
>
> Stream s = Console.OpenStandardOutput(1024);

Use:

BufferedStream s = new BufferedStream(Console.OpenStandardOutput());

> It's still 3.4 times slower.

Not if you optimize it properly.

> Verify it yourself.

I did.

There is no merit in comparing unoptimized code on .NET with optimized Java.

Java is also not significant faster on any of the SciMark2 benchmarks. The
only significant difference I have seen is on the Mersenne Twister PRNG
where Java is 2x slower than .NET.

John B. Matthews

unread,
Jun 3, 2008, 11:33:35 AM6/3/08
to
In article <epba4495e658920oe...@4ax.com>,
Razii <klgfsdf...@mail.com> wrote:

[...]
> Verify it yourself.
>
> http://shootout.alioth.debian.org/gp4/benchmark.php?test=mandelbrot&lang=cshar
> p&id=2
>
> vs
>
> http://shootout.alioth.debian.org/gp4/benchmark.php?test=mandelbrot&lang=javax
> x&id=0
>
>
> 3.4 times slower.

Indeed, I see C#/Mono = 7.15s and Java = 3.22s. I would say that Java
took (3.22s / 7.15s = 0.450) less that half as long as C#/Mono or that
Java was (7.15s / 3.22s = 2.220) over twice as fast. I don't see where
3.4 comes from. Just asking.

John
--
John B. Matthews
trashgod at gmail dot com
home dot woh dot rr dot com slash jbmatthews

Jon Harrop

unread,
Jun 3, 2008, 11:39:25 AM6/3/08
to
John B. Matthews wrote:
> Indeed, I see C#/Mono = 7.15s and Java = 3.22s. I would say that Java
> took (3.22s / 7.15s = 0.450) less that half as long as C#/Mono or that
> Java was (7.15s / 3.22s = 2.220) over twice as fast. I don't see where
> 3.4 comes from. Just asking.

FWIW, F#/Mono is 3x slower than F#/.NET on the SciMark2 benchmark. I'd like
to know how performance compares between these platforms for parallel code.

Does Java have anything comparable to .NET's Task Parallel Library?

Jon Skeet [C# MVP]

unread,
Jun 3, 2008, 12:19:22 PM6/3/08
to
On Jun 3, 4:39 pm, Jon Harrop <j...@ffconsultancy.com> wrote:
> FWIW, F#/Mono is 3x slower than F#/.NET on the SciMark2 benchmark. I'd like
> to know how performance compares between these platforms for parallel code.

If Razii is genuinely comparing Java with Mono (I haven't looked at
any of the figures) it's a silly test to start with (unless you're
specifically interested in Mono, of course). The vast majority of C#
code runs on .NET rather than Mono - and while I applaud the Mono
team's work, I seriously doubt that it has quite has much effort going
into it as Microsoft is putting into .NET. I'd expect .NET to
outperform Mono, and on microbencharks like these the difference could
be quite significant in some cases.

> Does Java have anything comparable to .NET's Task Parallel Library?

I haven't used it, but I've heard about Doug Lea's Fork/Join
framework:
http://gee.cs.oswego.edu/dl/papers/fj.pdf

One problem with creating anything like Parallel Extensions (which I
assume is what you meant - AFAIK the TPL is just part of Parallel
Extensions, although I could be misunderstanding you completely) for
Java is that it doesn't (currently) have closures other than anonymous
inner classes which are ugly as hell.

The state of closures in Java 7 is currently up in the air.

Jon

Razii

unread,
Jun 3, 2008, 12:49:33 PM6/3/08
to
On Tue, 03 Jun 2008 16:08:17 +0100, Jon Harrop <j...@ffconsultancy.com>
wrote:

> Java is still over 2x slower on both partialsums and
>the Mersenne Twister.

The partialsums is only slower due to trig accuracy required by Java's
specification. Your C# results are not accurate enough to satisfy
Java's specification. It's easy to solve this problem. Try this Java
version of partialsums. It's two times faster.

http://shootout.alioth.debian.org/gp4/benchmark.php?test=partialsums&lang=java&id=4

In binarytrees C# is twice slower. You haven't posted any workaround
yet.

Razii

unread,
Jun 3, 2008, 12:56:13 PM6/3/08
to
On Tue, 03 Jun 2008 11:33:35 -0400, "John B. Matthews"
<nos...@nospam.com> wrote:

>I don't see where
>3.4 comes from. Just asking.

Did you use -server flag? It's 7.578 vs 2.198 on my computer.
7.578 / 2.198 = 3.44


Razii

unread,
Jun 3, 2008, 1:06:11 PM6/3/08
to
On Tue, 03 Jun 2008 16:08:17 +0100, Jon Harrop <j...@ffconsultancy.com>
wrote:

> BufferedStream s = new BufferedStream(Console.OpenStandardOutput());


>
>and the entire program becomes 2.5x faster.

Yes, that was faster. I submitted it to shootout site. I am not sure
if it will be faster on Mono too but I will let Gouy test it.


Razii

unread,
Jun 3, 2008, 1:16:51 PM6/3/08
to
On Tue, 03 Jun 2008 16:18:34 +0100, Jon Harrop <j...@ffconsultancy.com>
wrote:

>There is no merit in comparing unoptimized code on .NET with optimized Java.

That's why posted it here so you can "optimize it". You fixed
mandelbrot but C# is still twice slower in three other benchmarks:

binarytrees
(the command line argument should be -server -Xms64m binarytrees)

http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=binarytrees&lang=javaxx&id=2
vs
http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=binarytrees&lang=csharp&id=0


revcomp
http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=revcomp&lang=javaxx&id=4
vs
http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=revcomp&lang=csharp&id=2


sumcol
http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=sumcol&lang=javaxx&id=4
vs
http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=sumcol&lang=csharp&id=0


also, C# significantly slower in recursion

http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=recursive&lang=javaxx&id=0
vs
http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=recursive&lang=csharp&id=0


>I have seen is on the Mersenne Twister PRNG where Java is 2x slower than .NET.

Post the benchmark. Let me see...


Razii

unread,
Jun 3, 2008, 1:31:31 PM6/3/08
to
On Tue, 3 Jun 2008 09:19:22 -0700 (PDT), "Jon Skeet [C# MVP]"
<sk...@pobox.com> wrote:

>If Razii is genuinely comparing Java with Mono (I haven't looked at
>any of the figures) it's a silly test to start with (unless you're
>specifically interested in Mono, of course).

If you have no clue what is this thread about, why post at all?

Jon Skeet [C# MVP]

unread,
Jun 3, 2008, 1:51:10 PM6/3/08
to
Razii <klj...@mail.com> wrote:
> >If Razii is genuinely comparing Java with Mono (I haven't looked at
> >any of the figures) it's a silly test to start with (unless you're
> >specifically interested in Mono, of course).
>
> If you have no clue what is this thread about, why post at all?

Well gee, you keep post URLs comparing Mono with Java. That's *not*
comparing .NET with Java - and is thus relatively pointless IMO. (It's
also made more pointless by you not mentioning in your blog post which
version of Java you're using, or which version of .NET.)

To make the conversation significant (well, as significant as this kind
of thing can be):

1) Don't bother posting about the Mono benchmarks at all. Keep it to
.NET and Java.
2) Explain the precise runtime environments.

The IO suggestions so far seem to be an indication of the general merit
of the benchmark, mind you.

--
Jon Skeet - <sk...@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com

Razii

unread,
Jun 3, 2008, 2:20:39 PM6/3/08
to
On Tue, 3 Jun 2008 18:51:10 +0100, Jon Skeet [C# MVP]
<sk...@pobox.com> wrote:

>Well gee, you keep post URLs comparing Mono with Java. That's *not*
>comparing .NET with Java - and is thus relatively pointless IMO. (It's
>also made more pointless by you not mentioning in your blog post which
>version of Java you're using, or which version of .NET.)

The link I posted was this:

http://kingrazi.blogspot.com/

It's clear what it is about.


Jon Harrop

unread,
Jun 3, 2008, 2:18:50 PM6/3/08
to

It makes no difference on Mono and the shootout does not test .NET.

Razii

unread,
Jun 3, 2008, 2:24:15 PM6/3/08
to
On Tue, 3 Jun 2008 18:51:10 +0100, Jon Skeet [C# MVP]
<sk...@pobox.com> wrote:

>The IO suggestions so far seem to be an indication of the general merit
>of the benchmark, mind you.

The criteria is same for both sides. For now C# is slower by wide
margin in these benchmarks. How about fixing them? If you can't, I
will conclude C# is just slower.

Mark Thornton

unread,
Jun 3, 2008, 2:32:38 PM6/3/08
to
Jon Harrop wrote:
> Mark Thornton wrote:
>> Rather amusing really as unintentional use of unbuffered IO is a
>> frequent cause of Java benchmarks running more slowly than they should.
>> It seems that .NET copied that characteristic as well.
>
> Yes. I've no idea why they do that. Isn't buffered IO a better default?!
>

I think the reasoning is simplicity --- you create what you want through
composition of a smaller number of classes. Otherwise you need more
classes or extra options on constructors to provide for all possible
cases. Unfortunately they spoiled this a bit by providing a few
composites (java.io.FileReader for example). It is also a bit confusing
that InputStreamReader includes some buffering, but adding buffering to
an already buffered stream doesn't usually increase the cost by much.

Mark Thornton

Jon Harrop

unread,
Jun 3, 2008, 2:33:41 PM6/3/08
to
Razii wrote:
> The criteria is same for both sides. For now C# is slower by wide
> margin in these benchmarks. How about fixing them?

I did.

> If you can't, I will conclude C# is just slower.

You had drawn that conclusion before you even tried to measure anything.

Mark Thornton

unread,
Jun 3, 2008, 2:37:53 PM6/3/08
to
Jon Skeet [C# MVP] wrote:
>
>> Does Java have anything comparable to .NET's Task Parallel Library?
>
> I haven't used it, but I've heard about Doug Lea's Fork/Join
> framework:
> http://gee.cs.oswego.edu/dl/papers/fj.pdf
>
I have used it and find it works quite well even without closures. I
haven't used .NET so can't compare them.

For more information and downloads of the package:
http://g.oswego.edu/dl/concurrency-interest/

Mark Thornton

Jon Skeet [C# MVP]

unread,
Jun 3, 2008, 2:37:47 PM6/3/08
to

That was the link you posted *initially*. Since then you have posted
multiple links to http://shootout.alioth.debian.org which is about
Mono.

Jon Harrop

unread,
Jun 3, 2008, 2:37:29 PM6/3/08
to
Mark Thornton wrote:
> Jon Skeet [C# MVP] wrote:
>>> Does Java have anything comparable to .NET's Task Parallel Library?
>>
>> I haven't used it, but I've heard about Doug Lea's Fork/Join
>> framework:
>> http://gee.cs.oswego.edu/dl/papers/fj.pdf
>>
> I have used it and find it works quite well even without closures. I
> haven't used .NET so can't compare them.

The Task Parallel Library is awesome, even though it is only a CTP for now.
I highly recommend it. For example, read the article:

"Surviving in the multicore era with Microsoft's ParallelFX" - The F#.NET
Journal, 30th April 2008
http://www.ffconsultancy.com/products/fsharp_journal/?cs

Jon Harrop

unread,
Jun 3, 2008, 2:37:57 PM6/3/08
to
Razii wrote:
> On Tue, 03 Jun 2008 16:08:17 +0100, Jon Harrop <j...@ffconsultancy.com>
> wrote:
>> Java is still over 2x slower on both partialsums and
>>the Mersenne Twister.
>
> The partialsums is only slower due to trig accuracy required by Java's
> specification. Your C# results are not accurate enough to satisfy
> Java's specification. It's easy to solve this problem. Try this Java
> version of partialsums. It's two times faster.

But still 2x slower than everything else and now 2x more bloated as well:

C 1.300s
C# 1.363s
Java 2.750s
Java 3.840s (original)

> In binarytrees C# is twice slower. You haven't posted any workaround
> yet.

Optimizing binarytrees is trivial because the benchmark is fundamentally
flawed. I described this in detail on the shootout mailing list and urged
the maintainers to persue well defined benchmarks but they did not take
heed.

Razii

unread,
Jun 3, 2008, 2:50:17 PM6/3/08
to
On Tue, 03 Jun 2008 19:37:57 +0100, Jon Harrop <j...@ffconsultancy.com>
wrote:

>But still 2x slower than everything else and now 2x more bloated as well:


>
>C 1.300s
>C# 1.363s
>Java 2.750s

that's not what I get

time java -server partialsums 2500000

0m1.697s

and for Mono I get

0m1.525s

Jon Skeet [C# MVP]

unread,
Jun 3, 2008, 2:50:21 PM6/3/08
to
Razii <klg...@mail.com> wrote:
> >The IO suggestions so far seem to be an indication of the general merit
> >of the benchmark, mind you.
>
> The criteria is same for both sides.

Um, the C# version (as posted on the site you've linked to below) uses
unbuffered IO while the Java version doesn't. They're just not doing
the same thing. Even if they were, that wouldn't give any meaningful
data about which language/platform "in general". It might help if you
happen to know that your code is going to require a huge amount of
recursion - to the extent that it's going to be the performance
bottleneck - *and* performance is your primary concern.

> For now C# is slower by wide margin in these benchmarks. How about
> fixing them? If you can't, I will conclude C# is just slower.

Feel free to draw that conclusion, while the rest of us instead
conclude that you can't claim that C# (which is a *language* after all,
not a platform) is slower or faster than another language.

Even running .NET rather than Mono will only go so far - you'd need to
run it on both 64 bit and 32 bit platforms, as the runtimes do
different things. (IIRC the 64 bit CLR uses tail recursion more heavily
than the 32 bit CLR, for instance.)

If I were to find a really slow JVM, would that prove that Java is a
slower *language* than C#?

I can easily write a benchmark where Java (under Hotspot) "beats" .NET:
just call a very small virtual method which is never overridden.
Hotspot will inline the call aggressively, as it is able to "undo" the
optimisation later on. .NET, with a single-pass JIT, won't do that.
Does that prove that Java is a faster language? No, not at all. It just
shows one area situation where it works better. It pretty much has to,
given that far more methods tend to be virtual in Java code than in
.NET code. I can probably find similar situations where .NET stomps
over Java (being able to create custom value types would probably be a
good starting point - force heap allocation and garbage collection in
Java but not .NET; even though it's fast, it's not free) - but that
wouldn't prove that .NET is faster than Java, either.

Jon Harrop

unread,
Jun 3, 2008, 2:48:16 PM6/3/08
to

Yes. Mono is extremely slow. Almost as slow as Java on this benchmark. As we
have seen, .NET is much faster...

Razii

unread,
Jun 3, 2008, 2:55:26 PM6/3/08
to
On Tue, 03 Jun 2008 19:33:41 +0100, Jon Harrop <j...@ffconsultancy.com>
wrote:

>> If you can't, I will conclude C# is just slower.


>
>You had drawn that conclusion before you even tried to measure anything.

What the heck? I measured everything and posted the linhk. That's how
the thread started.

BufferedStream didn't help in sumcol

using (StreamReader r = new StreamReader(new
BufferedStream(Console.OpenStandardInput())))

makes no difference.

The only fix you have made so far is to mandelbrot. What about the 4
other I mentioned?

Jon Skeet [C# MVP]

unread,
Jun 3, 2008, 2:55:25 PM6/3/08
to
Mark Thornton <mtho...@optrak.co.uk> wrote:
> > I haven't used it, but I've heard about Doug Lea's Fork/Join
> > framework:
> > http://gee.cs.oswego.edu/dl/papers/fj.pdf
>
> I have used it and find it works quite well even without closures.

Cool - that's good to hear. I'd be very surprised if closures didn't
make it even simpler to use (possibly with a bit of refactoring towards
single-method interfaces if necessary).

Given the rest of Doug Lea's work, I'd expect it to be good :)

> I haven't used .NET so can't compare them.

Here's a little example from a Mandelbrot benchmark I was writing a few
weeks ago (oh the irony).

Simple initial code:

public override void Generate()
{
int index = 0;
for (int row = 0; row < Height; row++)
{
for (int col = 0; col < Width; col++)
{
Data[index++] = ComputeMandelbrotIndex(row, col);
}
}
}

Now using Parallel Extensions, and the lamdba expressions of C# 3:

public override void Generate()
{
Parallel.For(0, Height, row =>
{
int index = row * Width;
for (int col = 0; col < Width; col++)
{
Data[index++] = ComputeMandelbrotIndex(row, col);
}
});
}

I can't imagine many transformations being simpler than that - and the
results are great.

See http://preview.tinyurl.com/58vfav for rather more :)

> For more information and downloads of the package:
> http://g.oswego.edu/dl/concurrency-interest/

Thanks, will take a look.

Razii

unread,
Jun 3, 2008, 2:57:42 PM6/3/08
to
On Tue, 3 Jun 2008 19:37:47 +0100, Jon Skeet [C# MVP]
<sk...@pobox.com> wrote:

>That was the link you posted *initially*. Since then you have posted
>multiple links to http://shootout.alioth.debian.org which is about
>Mono.

Huh? I will be polite for now and just say you didn't read the thread
carefully. The benchmark I tested are at that site. I don't have Mono.
I only have .NET.


Razii

unread,
Jun 3, 2008, 2:59:09 PM6/3/08
to
On Tue, 03 Jun 2008 19:37:57 +0100, Jon Harrop <j...@ffconsultancy.com>
wrote:

>But still 2x slower than everything else and now 2x more bloated as well:

The FastMath class can be separated and used instead of java's Math in
all cases. The bloat is ZERO.


Jon Skeet [C# MVP]

unread,
Jun 3, 2008, 2:57:57 PM6/3/08
to
Jon Harrop <j...@ffconsultancy.com> wrote:
> Mark Thornton wrote:
> > Jon Skeet [C# MVP] wrote:
> >>> Does Java have anything comparable to .NET's Task Parallel Library?
> >>
> >> I haven't used it, but I've heard about Doug Lea's Fork/Join
> >> framework:
> >> http://gee.cs.oswego.edu/dl/papers/fj.pdf
> >>
> > I have used it and find it works quite well even without closures. I
> > haven't used .NET so can't compare them.
>
> The Task Parallel Library is awesome, even though it is only a CTP for now.

Agreed. Now is a particularly good time to get into it, as the second
CTP has just been released:

http://blogs.msdn.com/pfxteam/archive/2008/06/02/8567093.aspx

> I highly recommend it. For example, read the article:
>
> "Surviving in the multicore era with Microsoft's ParallelFX" - The F#.NET
> Journal, 30th April 2008
> http://www.ffconsultancy.com/products/fsharp_journal/?cs

Or not, given that that's subscription only...

Razii

unread,
Jun 3, 2008, 3:00:07 PM6/3/08
to
On Tue, 03 Jun 2008 19:48:16 +0100, Jon Harrop <j...@ffconsultancy.com>
wrote:

>Yes. Mono is extremely slow. Almost as slow as Java on this benchmark. As we


>have seen, .NET is much faster...

That was a typo. I don't have Mono. I get that with .NET.


Razii

unread,
Jun 3, 2008, 3:04:31 PM6/3/08
to
On Tue, 3 Jun 2008 19:50:21 +0100, Jon Skeet [C# MVP]
<sk...@pobox.com> wrote:

>Um, the C# version (as posted on the site you've linked to below) uses
>unbuffered IO while the Java version doesn't. They're just not doing
>the same thing.

What benchmark are you talking about? Changing the line to

using (StreamReader r = new StreamReader(new
BufferedStream(Console.OpenStandardInput())))

didn't make a difference in sum-file benchmark.

By the way, StreamTokenizer is not buffered. It reads a byte each time
from the stream. It maybe that System.in is buffered by default in
Java.

Jon Harrop

unread,
Jun 3, 2008, 3:03:49 PM6/3/08
to
Razii wrote:
> On Tue, 03 Jun 2008 19:33:41 +0100, Jon Harrop <j...@ffconsultancy.com>
> wrote:
>>> If you can't, I will conclude C# is just slower.
>>
>>You had drawn that conclusion before you even tried to measure anything.
>
> What the heck? I measured everything...

You only measured unoptimized C#. I have optimized the C# for you but your
response has only been to cherry pick results that back the conclusion you
wanted to draw.

> The only fix you have made so far is to mandelbrot.

Have you already forgotten that you were not compiling the regular
expressions in the C# implementation of regexdna?

> What about the 4 other I mentioned?

You said ".NET is twice slower in four benchmarks: binarytrees, mandelbrot,
regexdna, sumcol.". I have already corrected two of your results (mandelbrot
and regexdna) and provided two more counter examples where .NET is >2x
faster than Java and explained why binarytrees is flawed.

Razii

unread,
Jun 3, 2008, 3:08:35 PM6/3/08