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!

6
  • 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. Commented Nov 20, 2011 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/... Commented Nov 20, 2011 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). Commented Nov 20, 2011 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. Commented Nov 20, 2011 at 17:59
  • Don't you think your hypothesis is a little bit biased? Commented Nov 20, 2011 at 18:19

5 Answers 5

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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?
+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.
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.

Comments

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.

Comments

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.

1 Comment

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.