473,883 Members | 1,576 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

benchmarks? java vs .net

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...enchmarks.html

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

Jun 27 '08
358 13276
Barry Kelly <ba***********@ gmail.comwrote:
Obviously I can't speak for your experience, but mine is certainly that
the two don't come together very often. More likely in the scientific
world than the business world, I suspect.

FWIW, when one adopts the test-first style of development, the ability
to create mocks (whether by inheritance or the proxy capabilities of the
CLR/etc.) and use dependency injection frameworks (inversion of control
pattern) to abstract away your dependencies becomes very important.
True.
It's then that the ability of the runtime to optimize virtual method
calls to statically dispatched calls becomes a lot more important,
because:

1) Usually, the only point of a method being virtual is so that it can
easily be mocked

2) Usually, when running "for real" and not for test, only a single
implementation of that method will be loaded into the runtime.
Absolutely. I don't dispute that at all - I just wonder how often those
virtual methods are both small enough to be inlined *and* critical for
performance.

I'm sure there are some cases where it makes a really huge difference -
but I suspect it makes a *slight* difference to a far greater
proportion of apps.
I wouldn't discard the utility of the virtual -static call
optimization so trivially.
One reason it's so important in Java of course is that methods are
virtual by default. C# (and VB.NET, I believe) methods are non-virtual
by default. The defaults wouldn't make a difference if every developer
diligently thought about whether or not to make a method virtual every
time they wrote it - but of course, few people (myself *not* included)
are that diligent.
Of course, some kind of more direct language or runtime support for
mocking and / or inversion of control might be a better solution than
willy-nilly making every method virtual, as that has other, more severe
repercussions for designability and testability - classes with virtual
methods being a lot harder to test due to the extra code paths.
Well, just because an interface has a virtual method doesn't mean it
has to be virtual in the implementing class. But yes, inheritence of
implementation certainly has a design cost associated with it.

--
Jon Skeet - <sk***@pobox.co m>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Jun 27 '08 #221
On Thu, 05 Jun 2008 18:54:02 +0100, Jon Harrop <jo*@ffconsulta ncy.com>
wrote:
>Given that my CPU (2.2GHz Athlon64 X2) predates yours and is roughly half as
fast on other benchmarks overall, it is clear that your result for F# is
anomalous: taking longer on a much faster machine.
Well, here is F#

http://shootout.alioth.debian.org/gp...ng=fsharp&id=0

and java

http://shootout.alioth.debian.org/gp...ng=javaxx&id=2

anyone can test it and see if they get different result. The only
ctiteria is using java -server -Xms64m (not -Xmx64m)

F# Mono is also slower than C# Mono according to the site.
Jun 27 '08 #222
Barry Kelly wrote:
Jon Harrop wrote:
>Jon Skeet [C# MVP] wrote:
Jon Harrop <jo*@ffconsulta ncy.comwrote:
That is Java outperforming C#, not .NET.

No, it's Java outperforming .NET calling a virtual method. It has
nothing to do with the code that the IL is generated in: if you have a
virtual method which isn't overridden, the .NET CLR will not inline
calls to it. The Hotspot VM will inline it until it first sees the
method being overridden. The difference here is in the jitting model,
not in the language.

Try it in F#, ensuring that the method is virtual and actually called
each time (consider that the method might be one which has side-
effects). I can't see how it would possibly have a different result.

This optimization can obviously be done statically by the compiler. There
is no assurance that F# will also fail to optimize this, particularly if
you write a functional equivalent:

We're not talking about "functional equivalents".
I know. That is why I said you are talking about C# and not .NET.
We're talking about virtual methods
That only exist in OOP.
that are callable by third-party code
That cannot be imposed in such a way that it prohibits static optimization.
written in any CLR language,
CLR languages are not necessarily capable of producing C#-compatible virtual
methods.
i.e. methods for which a MethodInfo instance can be obtained
from reflection, and for which MethodInfo.IsVi rtual returns true and
MethodInfo.IsFi nal returns false.
That does not obviate static optimization.
Any code in F# or any other language which doesn't compile to something
that can be loaded in MethodInfo form via System.Reflecti on doesn't
apply, because it simply isn't a virtual method.
Even if I use the FFI to enforce the generation of a virtual method there is
nothing to stop the F# compiler from inlining it when that is statically
possible (as it is in this case).

I'm not disagreeing with any of your statements. I am simply saying that
they do not apply to all .NET languages. Indeed, they only make sense in
object oriented languages.

--
Dr Jon D Harrop, Flying Frog Consultancy
http://www.ffconsultancy.com/products/?u
Jun 27 '08 #223
Jon Skeet [C# MVP] wrote:
Mark Thornton <mt*******@optr ak.co.ukwrote:
>>Pointless benchmark, of course, other than to show the inlining
capabilitie s of Hotspot in the face of a virtual method which hasn't
been overridden.
It does have real relevance. I have classes with multiple
implementation s, but quite frequently a given process will only use one
of the possible implementations .

Fair enough - but it's only significant if:
a) the implementation is small enough to inline
b) the method call would be a significant hit, i.e. it's a bottleneck
in the app

Obviously I can't speak for your experience, but mine is certainly that
the two don't come together very often. More likely in the scientific
world than the business world, I suspect.
I do vehicle routing algorithms, so although the application is sold to
businesses, its core is more scientific/mathematical in nature. Using
100% CPU is routine. I'm working on achieving that for multi core
machines as well.

Mark Thornton
Jun 27 '08 #224
Razii <nu*********@ma il.comwrote:

<snip>
tha's now 3.4 times faster than C# and F#. If anyone wants to test it,
On my box, where I don't have the server JVM installed at the moment,
the .NET version *was* much slower than the Java version, until I
forced the .NET GC into server mode, which made .NET merely "a bit
slower" than Java. Create BinaryTrees.exe .config with this in it:

<configuratio n>
<runtime>
<gcServer enabled="true" />
</runtime>
</configuration>

Then retry. It made a big difference on my box (although I don't
entirely trust the result on my box, as the disk is thrashing atm). See
what it does on yours.

--
Jon Skeet - <sk***@pobox.co m>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Jun 27 '08 #225
On Thu, 5 Jun 2008 22:31:41 +0100, Jon Skeet [C# MVP]
<sk***@pobox.co mwrote:
>On my box, where I don't have the server JVM installed at the moment,
In this case, the difference between client and server is only 3
seconds.
>until I
forced the .NET GC into server mode, which made .NET merely "a bit
slower" than Java. Create BinaryTrees.exe .config with this in it:

<configuration >
<runtime>
<gcServer enabled="true" />
</runtime>
</configuration>

Then retry.
Yes, this did make a big difference

0m25.368s (.NET with above included)
0m18.097s (client with -Xms512m -Xmx512m -XX:NewRatio=1)
0m15.218s (-server -Xms512m -Xmx512m -XX:NewRatio=1 )

Jun 27 '08 #226
On Thu, 05 Jun 2008 17:03:27 -0500, Razii <ni*******@mail .comwrote:
>>On my box, where I don't have the server JVM installed at the moment,
If you have JDK installed, you do have server. Change your path so
that Windows find java.exe in JDK directory before it finds the one in
System32 directory.

Jun 27 '08 #227
Razii <ni******@mail. comwrote:
On Thu, 05 Jun 2008 17:03:27 -0500, Razii <ni*******@mail .comwrote:
>On my box, where I don't have the server JVM installed at the moment,

If you have JDK installed, you do have server. Change your path so
that Windows find java.exe in JDK directory before it finds the one in
System32 directory.
Ah, handy.

Okay, here are my timings then - wallclock only:

Java: ~15s
..NET: ~28s

I'll try to find more GC settings - a quick look at Perfmon suggests
it's spending most of its time there. It could well be that Java's GC
is better for this test scenario.

--
Jon Skeet - <sk***@pobox.co m>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Jun 27 '08 #228
On Fri, 06 Jun 2008 01:54:46 +0100, Jon Harrop <jo*@ffconsulta ncy.com>
wrote:
>This is now 2x faster than Java again but the benchmark is flawed so we can
keep doing this forever.
It's not. Your version is exactly same speed as C# (in fact slightly
slower): 0m28.575s. (I was getting 25.38 with C#).

Skeet also got same numbers as me, basically .NET is 1.6 to 2 two
times slower.
Jun 27 '08 #229
Barry Kelly wrote:
Jon Harrop wrote:
>Barry Kelly wrote:
We're talking about virtual methods

That only exist in OOP.

Like it or not, virtual methods are part of the CLR (and JVM), and if
you want your language, be it functional, procedural, logic,
object-oriented, data-flow oriented, functional-reactive,
actor-oriented, or using any other paradigm, to interact with code
written for that platform, then it needs to support at least calling
virtual methods...
What is the difference between the IL for a call to a virtual method and the
IL for a call to a non-virtual method?
FWIW, virtual methods, in isolation, aren't so OOP-bound as you assert.
You can't cite a language that provides virtual methods without being an OOP
language because having virtual methods makes it an OOP language.
Virtual methods are functions dynamically dispatched over a single type.
They implement a limited form of runtime overload resolution. Lisp-style
(CLOS) multi-dispatch is effectively fully orthogonal runtime overload
resolution. If a functional language is to support dynamic features like
runtime code generation and code loading, it would do well to support
overload resolution at runtime too, but further generalizing it to
pattern matching, rather than just type matching.
There are many other forms of dispatch but that does not mean that virtual
methods transcend OOP.
written in any CLR language,

CLR languages are not necessarily capable of producing C#-compatible
virtual methods.

Sure. That's why we have definitions like CLS-producer and CLS-consumer,
as well as a distinction between correctness and verifiability.

To the extent that a language is a CLS-producer and intends to produce
verifiable code, then it is constrained not to break the virtual method
contract.

To the extent that a language is only a CLS-consumer, and only produces
correct code, then it is free to break any contracts it likes, including
non-type-safe constructs (aka unsafe code in C#). A compromise is
possible, of course, with appropriate annotations & documentation, like
C++/CLI and C# itself.

CLS-constrained code is not necessarily merely "C#-compatible"; it is
intended to be compatible with *every* language running on the CLR, to
the extent that those languages are CLS-consumers.
The distinction is academic (see below).
>I'm not disagreeing with any of your statements. I am simply saying that
they do not apply to all .NET languages. Indeed, they only make sense in
object oriented languages.

No, they make sense for languages that are intended to (1) produce
verifiable code and (2) be CLS-producer languages.
My statement was equivalent to (2) because your notion of "CLS-producer"
requires OOP.
Limit (2) and you limit your language's market; limit (1) and you limit
the viability of your language as an application/web server development
platform.

F# has its own syntax to produce code that can be called by other CLS
consumers,
What do you mean by "has its own syntax"?
so it is a CLS-producer (I don't know to how complete a degree).
Again, that is an academic distinction. It is useless in practice.

For example, the RedGate ANTS profiler for C# breaks when it encounters ILX.
So if I sell you a ".NET library" that happens to be written in F# it can
break your existing tools and libraries. That could be commercial suicide
so nobody takes that risk.

That means that, in practice, I cannot sell libraries written in F# to
general .NET programmers. So instead of using F# as a "CLS-producer" we
write our own compilers that generate C# source code and we sell that
instead. Our advertising even states "100% managed C#" because it gives
customers a warm fuzzy feeling and they are more likely to buy.

So I recommend forgetting about this utopian idea of CLS-producers and look
simply at what products are shipping today. Incidentally, you said that
such issues would limit a language's market but our products for F# users
sell 10x more than our products for C# users.
Since you can write virtual methods in F# (using the "abstract"
member specification), an equivalent test to the one Jon Skeet posted
would necessarily include using virtual methods.
For some subjective notion of equivalence, yes.
The whole point of the test is to micro-benchmark single-type polymorphic
dispatch.
Ironically, that does not satisfy your implied notion of equivalence because
it is not specific to virtual methods and OOP.

--
Dr Jon D Harrop, Flying Frog Consultancy
http://www.ffconsultancy.com/products/?u
Jun 27 '08 #230

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

Similar topics

80
3572
by: tech | last post by:
Hi, i have the following problem In file1.h namespace A { class Bar { void foo();
318
11198
by: King Raz | last post by:
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++?
0
9936
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
9791
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
11137
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
10742
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...
0
9571
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7970
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7123
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
5797
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4215
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.