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 Harrop wrote:
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.
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.
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 and, for deep interaction, providing virtual methods for
others to call.

FWIW, virtual methods, in isolation, aren't so OOP-bound as you assert.
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.
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.
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.
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.

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, so it is a CLS-producer (I don't know to how complete a
degree). 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. The whole point of the
test is to micro-benchmark single-type polymorphic dispatch.

-- Barry

--
http://barrkel.blogspot.com/
Jun 27 '08 #231
Jon Skeet wrote:
Barry Kelly <ba***********@ gmail.comwrote:
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 was more focusing on the ability of the JVM to optimize a dynamic
dispatch to a static dispatch, rather than virtual method inlining per
se.

Both can be relevant, but I think the first is more important (certainly
for Java code) than the second; but the first also has applications more
generally to IoC etc.

-- Barry

--
http://barrkel.blogspot.com/
Jun 27 '08 #232
Jon Skeet [C# MVP] wrote:
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.
Exactly. And avoiding that issue does not make anything harder on .NET.

The converse is not true of Java though. For example, having to avoid tail
calls because they have never been properly implemented in the JVM makes
some things much harder.

--
Dr Jon D Harrop, Flying Frog Consultancy
http://www.ffconsultancy.com/products/?u
Jun 27 '08 #233
Jon Skeet [C# MVP] wrote:
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.
Yes, that also more than doubled the performance.

Here is an alternative (parallelized) F# version that also more than doubles
the performance:

#light

#I @"C:\Program Files\Reference Assemblies\Micr osoft\Framework \v3.5"
#r @"C:\Program Files\Microsoft Parallel Extensions Jun08
CTP\System.Thre ading.dll"

[<CompilationRep resentation(Com pilationReprese ntationFlags.Pe rmitNull)>]
type 'a tree = Empty | Node of 'a tree * 'a * 'a tree

let inline make0 i = Node(Empty, i, Empty)

let inline make1 i =
let t = make0 (2*i)
Node(t, i, t)

let inline make2 i =
Node(make1 (2*i - 1), i, make1 (2*i))

let rec make_aux i = function
| 2 -make2 i
| d -Node(make_aux (2*i - 1) (d-1), i, make_aux (2*i) (d-1))

let make i = function
| 0 -make0 i
| 1 -make1 i
| d -make_aux i d

let rec check = function
| Empty -0
| Node(l, i, r) -i + check l - check r

let min_depth = 4
let max_depth =
let n = try int Sys.argv.[1] with _ -20
max (min_depth + 2) n
let stretch_depth = max_depth + 1

let loop_depth d () =
let niter = 1 <<< (max_depth - d + min_depth)
let mutable c = 0
for i = 1 to niter do
c <- c + check(make i d) + check(make (-i) d)
niter, d, c

let main() =
let c = check (make 0 stretch_depth)
Printf.printf "stretch tree of depth %i\t check: %i\n" stretch_depth c
let long_lived_tree = make 0 max_depth
let futures =
[ for d in min_depth .. 2 .. max_depth ->
System.Threadin g.Tasks.Future. Create(loop_dep th d) ]
for future in futures do
let niter, d, c = future.Value
printf "%i\t trees of depth %i\t check: %i\n" (2 * niter) d c
Printf.printf "long lived tree of depth %i\t check: %i\n"
max_depth (check long_lived_tree )

do
let t = new System.Diagnost ics.Stopwatch()
t.Start()
main()
printf "%d\n" t.ElapsedMillis econds

This is now 2x faster than Java again but the benchmark is flawed so we can
keep doing this forever.

--
Dr Jon D Harrop, Flying Frog Consultancy
http://www.ffconsultancy.com/products/?u
Jun 27 '08 #234
Jon Skeet [C# MVP] wrote:
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.
The command line options that Razii chose effectively turn off the GC.

--
Dr Jon D Harrop, Flying Frog Consultancy
http://www.ffconsultancy.com/products/?u
Jun 27 '08 #235
On Fri, 06 Jun 2008 02:35:44 +0100, Jon Harrop <jo*@ffconsulta ncy.com>
wrote:
>Here is another F# implementation that is much faster than your Java
(again):
It's not. It's slower. Obviously we don't get the same results. Let a
third person test it. Perhaps Skeet has F#.

Jun 27 '08 #236
Razii wrote:
Now here is a different version of MersenneTwister than what you
posted.

http://pastebin.com/f72f8838d
...
$ 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.
For 10^9 ints I get:

Java: 13.5s
F#: 16.7s

--
Dr Jon D Harrop, Flying Frog Consultancy
http://www.ffconsultancy.com/products/?u
Jun 27 '08 #237
On Fri, 06 Jun 2008 02:55:49 +0100, Jon Harrop <jo*@ffconsulta ncy.com>
wrote:
>For 10^9 ints I get:

Java: 13.5s
F#: 16.7s
Ok, then this MersenneTwister is no longer twice slower.

Can you post the C# and F# versions (add the exact method that tests
it). You can use pastebin.com
Jun 27 '08 #238
On Fri, 06 Jun 2008 02:46:48 +0100, Jon Harrop <jo*@ffconsulta ncy.com>
wrote:
>
The command line options that Razii chose effectively turn off the GC.
They don't.

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

stretch tree of depth 21 check: -1
[GC 196608K->49364K(491520K ), 0.1513998 secs]
[GC 245972K->49372K(491520K ), 0.0885678 secs]
[GC 245980K->49384K(491520K ), 0.0668613 secs]
[GC 245992K->49384K(491520K ), 0.0972670 secs]
[GC 245992K->49384K(491520K ), 0.0669637 secs]
[GC 245992K->49392K(461696K ), 0.0675055 secs]
[GC 216176K->49520K(428992K ), 0.1238719 secs]
[GC 216304K->49520K(464000K ), 0.0010244 secs]
[GC 197488K->49520K(410176K ), 0.0008281 secs]
2097152 trees of depth 4 check: -2097152
[GC 197488K->49536K(464384K ), 0.0008021 secs]
[GC 193024K->49520K(464960K ), 0.0012254 secs]
[GC 193008K->49504K(465728K ), 0.0015697 secs]
[GC 193888K->49520K(465088K ), 0.0009092 secs]
[GC 193904K->49536K(468416K ), 0.0008899 secs]
[GC 198400K->49536K(466880K ), 0.0008026 secs]
[GC 198400K->49520K(472128K ), 0.0010054 secs]
[GC 205360K->49520K(470144K ), 0.0009445 secs]
[GC 205360K->49520K(476480K ), 0.0009811 secs]
[GC 213808K->49520K(474240K ), 0.0008553 secs]
524288 trees of depth 6 check: -524288
[GC 213808K->49536K(481024K ), 0.0008600 secs]
[GC 222848K->49520K(478720K ), 0.0009234 secs]
[GC 222832K->49520K(485568K ), 0.0008998 secs]
[GC 231984K->49520K(483328K ), 0.0008445 secs]
[GC 231984K->49520K(489984K ), 0.0008858 secs]
[GC 240880K->49504K(487808K ), 0.0008590 secs]
[GC 240864K->49536K(494080K ), 0.0008913 secs]
[GC 249216K->49504K(492032K ), 0.0012131 secs]
131072 trees of depth 8 check: -131072
[GC 249184K->49536K(497856K ), 0.0009522 secs]
[GC 256960K->49536K(496000K ), 0.0008328 secs]
[GC 256960K->49536K(501312K ), 0.0009298 secs]
[GC 264064K->49520K(499648K ), 0.0008124 secs]
[GC 264048K->49536K(504384K ), 0.0008989 secs]
[GC 270400K->49536K(502912K ), 0.0008489 secs]
[GC 270400K->49536K(507136K ), 0.0009511 secs]
[GC 276032K->49520K(505792K ), 0.0020848 secs]
32768 trees of depth 10 check: -32768
[GC 276016K->49584K(509568K ), 0.0009982 secs]
[GC 281072K->49520K(508352K ), 0.0010441 secs]
[GC 281008K->49680K(511680K ), 0.0011986 secs]
[GC 285584K->49632K(510656K ), 0.0011478 secs]
[GC 285536K->49600K(513536K ), 0.0011361 secs]
[GC 289344K->49584K(512640K ), 0.0009221 secs]
8192 trees of depth 12 check: -8192
[GC 289328K->50128K(515200K ), 0.0019249 secs]
[GC 293264K->49808K(514368K ), 0.0013610 secs]
[GC 292944K->50256K(516672K ), 0.0026040 secs]
[GC 296464K->49936K(515968K ), 0.0018862 secs]
[GC 296144K->49632K(517824K ), 0.0009684 secs]
[GC 298336K->50272K(517312K ), 0.0023415 secs]
[GC 298976K->50160K(518848K ), 0.0020201 secs]
2048 trees of depth 14 check: -2048
[GC 300912K->51296K(518336K ), 0.0043586 secs]
[GC 302048K->50160K(519360K ), 0.0021542 secs]
[GC 302000K->50096K(518912K ), 0.0018978 secs]
[GC 301936K->50032K(520064K ), 0.0017406 secs]
[GC 303408K->51504K(519744K ), 0.0049608 secs]
[GC 304880K->49920K(520192K ), 0.0015220 secs]
512 trees of depth 16 check: -512
[GC 303616K->57844K(519936K ), 0.0258907 secs]
[GC 311540K->57748K(514816K ), 0.0083801 secs]
[GC 306068K->60308K(517056K ), 0.0134347 secs]
[GC 308628K->62864K(511296K ), 0.0258077 secs]
[GC 304784K->60912K(509376K ), 0.0125694 secs]
[GC 302832K->57056K(514432K ), 0.0036414 secs]
128 trees of depth 18 check: -128
[GC 299104K->77972K(514048K ), 0.0723174 secs]
[GC 320020K->86728K(494080K ), 0.0540681 secs]
[GC 308424K->120252K(504064 K), 0.1391573 secs]
[GC 341948K->119644K(476544 K), 0.0396110 secs]
[GC 313820K->117212K(490304 K), 0.0492557 secs]
[GC 311388K->114764K(491392 K), 0.0430719 secs]
[GC 310028K->113420K(490304 K), 0.0325961 secs]
[GC 308684K->112092K(494912 K), 0.0283435 secs]
32 trees of depth 20 check: -32
long lived tree of depth 20 check: -1

real 0m15.210s
user 0m0.000s
sys 0m0.015s

Jun 27 '08 #239
Jon Harrop <jo*@ffconsulta ncy.comwrote:
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.

The command line options that Razii chose effectively turn off the GC.
No they don't. They allocate a fixed sized heap (512M), one with a an
equal size of old/new spaces, but one which is still garbage collected.

The test creates a total of 305135616 instances of TreeNode. Without
garbage collection, each node couldn't even take 2 bytes without
running out of memory.

--
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 #240

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,...
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...
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
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
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.