473,883 Members | 1,674 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 13269
Jon Skeet [C# MVP] wrote:
Mark Thornton <mt*******@optr ak.co.ukwrote:
>>(Another nail in the coffin of the claim that ".NET is twice as slow as
Java" though,
>I don't see much in these benchmarks of the sort of code where the more
mature HotSpot JIT could be expected to outshine .NET.

As it is, Java outperforms .NET (on my box) by about 3:1.
Making GetNumber non-virtual, and .NET outperforms Java (on my box)
about about 2:1.

Pointless benchmark, of course, other than to show the inlining
capabilities of Hotspot in the face of a virtual method which hasn't
been overridden.
It does have real relevance. I have classes with multiple
implementations , but quite frequently a given process will only use one
of the possible implementations .

Mark Thornton
Jun 27 '08 #211
Razii wrote:
On Wed, 4 Jun 2008 23:07:29 +0100, Jon Skeet [C# MVP]
<sk***@pobox.co mwrote:
>Oh indeed. The fact that there's both Math and StrictMath is
particularly nice. It would be interesting to see a port of StrictMath
for .NET.

Since 1.4 Math just calls StrictMath for sin and cos. That's how sin
and cos got slower since 1.4. However, there is solution to it.

http://pastebin.com/f126f0c27
That might be what appears in the library source, but it isn't what
actually happens once a call has been compiled.

Mark Thornton

Jun 27 '08 #212
Jon Harrop <jo*@ffconsulta ncy.comwrote:
This optimization can obviously be done statically by the compiler.
No - this optimization cannot be done statically for runtimes that
support dynamic code loading, as the CLR and JVM do...

I just posted a working example where the optimization is done, so it is
clearly not impossible. The only question is (subjectively) was my code
equivalent.
Is your method virtual, and called virtually? If not, then it's not
equivalent. If it is, then the JIT can't inline 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 #213
Mark Thornton <mt*******@optr ak.co.ukwrote:
Pointless benchmark, of course, other than to show the inlining
capabilities of Hotspot in the face of a virtual method which hasn't
been overridden.

It does have real relevance. I have classes with multiple
implementations , 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.

--
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 #214
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". We're talking about
virtual methods that are callable by third-party code written in any CLR
language, 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.

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.

-- Barry

--
http://barrkel.blogspot.com/
Jun 27 '08 #215
On Thu, 05 Jun 2008 19:01:42 +0100, Jon Harrop <jo*@ffconsulta ncy.com>
wrote:
>[<CompilationRep resentation(Com pilationReprese ntationFlags.Pe rmitNull)>]

before the line:

type 'a tree = ...

and then try compiling with optimizations enabled:

fsc -O3 binarytrees.fs
fsc -O3 binarytreesf.fs

binarytreesf.fs (23,30): warning FS0062: This construct is for
compatibility with
OCaml. The expression form 'expr.(expr)' is for use when OCaml
compatibility is
enabled. In F# code you may use 'expr.[expr]'. A type annotation may
be require
d to indicate the first expression is an array. This warning can be
disabled usi
ng '--ml-compatibility', '--no-warn 62' or '#nowarn "62"'

binarytreesf.fs (23,16): warning FS0062: This construct is for
compatibility with
OCaml. Consider using the overloaded operator 'int' instead. This
warning can b
e disabled using '--ml-compatibility', '--no-warn 62' or '#nowarn
"62"'

$ time binarytreesf 20
stretch tree of depth 21 check: -1
2097152 trees of depth 4 check: -2097152
524288 trees of depth 6 check: -524288
131072 trees of depth 8 check: -131072
32768 trees of depth 10 check: -32768
8192 trees of depth 12 check: -8192
2048 trees of depth 14 check: -2048
512 trees of depth 16 check: -512
128 trees of depth 18 check: -128
32 trees of depth 20 check: -32
long lived tree of depth 20 check: -1

real 0m58.576s
user 0m0.015s
sys 0m0.015s

not it gets same time as C#
Jun 27 '08 #216
Razii wrote:
F# Mono is also slower than C# Mono according to the site.
That does not surprise me. Mono is much less efficient than .NET at handling
the abstractions that F# uses. The SciMark2 benchmark in F# is 3x faster
on .NET than Mono, for example.

--
Dr Jon D Harrop, Flying Frog Consultancy
http://www.ffconsultancy.com/products/?u
Jun 27 '08 #217
Jon Harrop <jo*@ffconsulta ncy.comwrote:
CLR languages are not necessarily capable of producing C#-compatible virtual
methods.
At that point the situation I originally described is no longer
applicable then, is it? Here's what I wrote:

<quote>
Pointless benchmark, of course, other than to show the inlining
capabilities of Hotspot in the face of a virtual method which hasn't
been overridden.
</quote>

If the method isn't virtual (at the .NET IL level) then you're not
reproducing the situation in which Java outperforms .NET.

--
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 #218
On Thu, 05 Jun 2008 18:00:14 +0100, Jon Harrop <jo*@ffconsulta ncy.com>
wrote:
>Try to optimize this one, for example:

http://www.math.sci.hiroshima-u.ac.j.../MTRandom.java

F# is 2x faster than this Java (and shorter, and more composable, and ...).
Though you have not given F# and C# version, I did test the above
class. Tell me if I did anything wrong.

public class test2
{
public static void main (String[] args)
{

MTRandom mt = new MTRandom ();
for (int i = 0;i < 100000000;i++)
{
mt.next (32);
}
}
}

$ time java -server test2
real 0m3.301s

$ time java test2
real 0m4.265s

Now here is a different version of MersenneTwister than what you
posted.

http://pastebin.com/f72f8838d

let's test this version

public class test2
{
public static void main (String[] args)
{
MersenneTwister Fast mt = new MersenneTwister Fast ();

for (int i = 0;i < 100000000;i++)
{
mt.nextInt();
}
}
}

$ time java -server test2

real 0m1.012s
user 0m0.000s
sys 0m0.031s

$ time java test2

real 0m1.966s
user 0m0.000s
sys 0m0.030s

This version is already 3.2 times faster than the link you posted.
Jun 27 '08 #219
On Thu, 05 Jun 2008 18:54:02 +0100, Jon Harrop <jo*@ffconsulta ncy.com>
wrote:
>$ time java -server -Xms64m binarytrees 20 (Java)
...
real 0m36.328s
user 0m0.031s
sys 0m0.046s

This takes 69s here.
On my comp that takes 32 seconds. However, it's possible to double the
speed again by using these flags:

$ time java -server -Xms512m -Xmx512m -XX:NewRatio=1 binarytrees 20

stretch tree of depth 21 check: -1
2097152 trees of depth 4 check: -2097152
524288 trees of depth 6 check: -524288
131072 trees of depth 8 check: -131072
32768 trees of depth 10 check: -32768
8192 trees of depth 12 check: -8192
2048 trees of depth 14 check: -2048
512 trees of depth 16 check: -512
128 trees of depth 18 check: -128
32 trees of depth 20 check: -32
long lived tree of depth 20 check: -1

real 0m16.955s
user 0m0.015s
sys 0m0.015s

tha's now 3.4 times faster than C# and F#. If anyone wants to test it,
(C#)
http://shootout.alioth.debian.org/gp...ng=csharp&id=0

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

(F#)
http://shootout.alioth.debian.org/gp...ng=fsharp&id=0

Jun 27 '08 #220

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
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...
1
10844
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
10410
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
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...
0
7122
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
5990
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4609
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
3
3231
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.