3

I am working on a school project, where I need to develop a hypothesis to be verified or falsified. My hypothesis is that C# execution time is faster than Java execution time on Windows, because C# is developed by Microsoft. Some of you might already know the answer to this hypothesis, and there have probably been studies that document this. But it does not matter, i just need to make this project myself.

So i would like some ideas on areas to focus on, and how to measure them?

P.S It should not be too complicated.

Thanks!

Pawan Mishra
  • 7,212
  • 5
  • 29
  • 39
Kenci
  • 4,794
  • 15
  • 64
  • 108
  • 6
    The problem with this hypothesis is that it's *very* broad. You can probably find plenty of areas where it's true and plenty of areas where it's false; and you'll find a sizable set of applications whose performance is dictated by one kind but not by the other. –  Nov 20 '11 at 16:51
  • I agree with @delnan. If you want to make it simple [as your question suggests], I would focus on one aspect alone: Memory access/garabae collection/Floating point arithmetic calculations/... – amit Nov 20 '11 at 16:53
  • Well the JVM JIT is rather excellent at the whole math/bit twiddling stuff (i.e. as fast as C++) and I assume .NET JIT will be not far behind - certainly a try worth but I'd be surprised at much difference. I also don't see how memory accesses would be vastly influenced by the language especially considering the overhead itself. Testing memory barriers would be interesting though and the GC is a really good idea (although complicated to measure considering all the different variants available). – Voo Nov 20 '11 at 17:05
  • My question is a little unclear. What i mean is that execution time is faster with C# than Java, on the areas that i am asking for ideas on. – Kenci Nov 20 '11 at 17:59
  • Don't you think your hypothesis is a little bit biased? – Albin Sunnanbo Nov 20 '11 at 18:19
  • Students being asked this kind of question makes my blood boil. You take two languages built roughly the same way and ask which one is faster? It shows a total ignorance of what performance is really about. It is about the details of what a specific program actually does *[as in this example](http://stackoverflow.com/questions/926266/performance-optimization-strategies-of-last-resort/927773#927773)*. It is not about generalities far above where the rubber meets the road. – Mike Dunlavey Nov 20 '11 at 20:49

5 Answers5

4

Some things I would test:

The time to open a file, write a line to it, and close it.

The time to open a network connection.

The time to open a database connection, write a single byte to it, and then close the connection.

The time to create and populate an array, a standard ArrayList, and a generic ArrayList.

The time to do sorting, using different algorithms.

The time to run a large loop.

dnuttle
  • 3,810
  • 2
  • 19
  • 19
  • 1
    The time to open a database connection tells you something about the database driver/library, but nothing about the language that is used to write the program. And how do you ensure that your C# and Java programs are equivalent? I know C# better than I know Java, so I'd expect that when I write a program in C# it will be more efficient than if I write it in Java, simply because I know the language, platform and compiler better. How do you write two "equal" programs in different languages? – jalf Nov 20 '11 at 18:31
  • +1: If it is true that C# is better on Windows, it should be C#'s interaction with the OS which is faster than Java's. Otherwise you would expect C# or Java to be consistently faster across OSes. However, I suspect where C# has an advantage is integration with Windows specific features rather than performance. – Peter Lawrey Nov 21 '11 at 08:06
2

The problem with this hypothesis is that I only have to find one counterexample to disprove it. And there's literally an unlimited number of programs you can write, so it is impossible to verify your hypothesis.

Even if you narrow it down to, say, "C# is faster than Java at sorting", I can still write an unlimited number of programs which perform sorting. And again, just one of them has to be faster in their Java implementation and your hypothesis is shot.

The other problem is that neither C# nor Java "has a speed".

Microsoft's C# compiler and their .NET implementation in their most recent versions have certain performance characteristics, and Oracle's most recent JVM version and most recent Java compiler version have certain performance characteristics, but that says nothing about C# or Java in general. What about the C# 2.0 compiler? What about the Mono C# compiler?

Comparing the performance of languages is meaningless. Languages don't have a speed.

jalf
  • 243,077
  • 51
  • 345
  • 550
0

I would personally focus on some of the most usual and everyday tasks - loops, string operations, arrays/lists, integer and floating point calculations, file operations. For measurements can you use the Stopwatch in C# (the most precise native .NET measuring solution). I don't know Java, but there is also a StopWatch class and it's purpose should be the same.

Martin Zikmund
  • 38,440
  • 7
  • 70
  • 91
0

Well first of all read this here - yes that includes one linked article (well this one is great ). If you don't we can stop right here because you'll only measure garbage. And yes that problem also exists for C# to some degree.

Also it depends on what you measure with C# - using unsafe code can give nice performance improvements at the cost of basically all the disadvantages of unmanaged languages. And what switches you use for the programs - not using -server for Java would be a really good idea to make C# look better than it is ;)

What reasonable benchmarks are? Well some simple math problem is usually nice to show (and both JITs are probably quite good at doing it so don't hope for too much differences - which is also an answer). Then maybe some benchmarks that show how good the JITs are at optimizing stuff - CSE, virtual inlining, etc. That then probably depends on how much you know about optimization in general.

Also certainly interesting is testing latency/time for a full/partial garbage collection run.

Community
  • 1
  • 1
Voo
  • 29,040
  • 11
  • 82
  • 156
0

My hypothesis is that C# execution time is faster than Java execution time on Windows, because C# is developed by Microsoft

Your wording is not very clear here. Is the suspected cause part of the hypothesis? Then you would have to verify how C# had turned out if it had been written by somebody other than Microsoft. To do this with any degree of reliability would require actually implementing C# for Windows from scratch.

Moreover, the statement "C# execution time is faster than Java execution time on Windows" is not well defined: execution time of what? If quite likely there are areas/programs where C# outperforms Java, and other areas where Java outperforms C#.

To make the hypothesis testable, you need to narrow it down, for instance to a particular program, that can be implemented nearly unchanged in either programming language, on a particular input, on a particular implementation of the JVM / CLR, on a particular computer. Yes, that claim won't be as useful, but at least its testable.

meriton
  • 68,356
  • 14
  • 108
  • 175
  • My question is a little unclear. What i mean is that execution time is faster with C# than Java, on the areas that i am asking for ideas on. – Kenci Nov 20 '11 at 17:59