May 9, 2010 C#, Java, MasterDiploma, Opinion
May 9, 2010 C#, Java, MasterDiploma, Opinion
Is CLR worse than JVM or it is just because my code is bad?
Today I had conversation with one man, who is great defender and evangelist of Java related technologies.
We talked about some algorithm implemented by me with C#. That is implementation of SOM algorithm and Concurrency stuff for it. My concurrency implementation doesn’t show time improvements unless grid size is big. He was able to achive better result with small grid sizes.
There could mean two reasons:
Taking into consideration that I’m getting better results when grid is of bigger sizes I could suppose that in my algorithm there is code which takes constant (or near that) time and is not paralleled.
When I look at picture of Task Manager when my programm is executing I see that second processor has gaps when it does nothing:
This could mean only one: I need to take better look what else is executed in one thread in my application and could be paralleled.
Converting C# code to Java
But back to that man and Java. I said to myself that it is possible to move my code to Java if something.
C# to Java Converter
Download C# to Java Converter demo version from here. Since it is demo you could not convert more than 1000 lines of your code. Order costs 119$.
Because of that I was forced to remove all not necessary code. I removed all concrete classes that I’m not using and GUI, but that did not help. I did not know how much should I delete more.
Number of lines in my project/solution
I googled for line numbers in C# and found this nice tool:
Now I know that my program has about 4000 lines of code. I left about 980 lines of code in two projects that I needed and was porting them to Java separately.
Converter GUI
And converted them to Java:
Is conversion an easy task?
Conversion could be painful if you have a lot of code that interacts with system, like threads, reading and writing to files, reading configuration file, etc.
Also it was not able to recognize ‘var’ keyword. It shows me this:
I moved back to my C# code and changed all var to the explicit types. And regenerated Java code.
There were some troubles when I’m delivering from List<T> and doing some stuff around that.
This code:
I rewrote manually to:
Also Converter was not able to convert this:
The biggest challenge is ThreadPool and synchronizing threads tech-nicks. This requires lot of google search that shows me that instead of ManualResetEvent I could use CyclicBarrier and how to utilize thread queuing in Java.
P/S I need to find gaps in my code to show that at least CLR and myself are not so much bad things in this world :)
Markdown | Result |
---|---|
*text* | text |
**text** | text |
***text*** | text |
`code` | code |
~~~ more code ~~~~ |
more code |
[Link](https://www.example.com) | Link |
* Listitem |
|
> Quote | Quote |
If you would really want to make a fair comparison then pls do the manual conversion.
And don't forget about http://jcip.net/.
it would be very interesting to hear the end of the story… please, don't forget to tell everybody :)
I spent almost all night (till 5am) trying to find weak places in my implementation. And found lot of them.
First of all CLR has to many ways to synch threads… I was using one of the slowest. Also found that I was doing to much work scheduling threads… In case with quick algorithms it is not good to pass all params through objects…
I improved my code, so now have better performance for grids 25×25, but that is not enought… need to work more… and learn Java Concurrency concurrently ;)
Andrii, of course you will hear end of story… :)