C# vs Java, Docker #767
Kinematics
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
So, I was recently reminded of Dave's video on C# vs Java. At the time it was first posted I recognized that the version he used for C# had a problem with it that led to lower performance.
It's been several months since the video was posted, and Dave hasn't been doing much. With my latest improvements to my own code, I wanted to take a look at the two solutions to see how they compare now.
This is run on an AMD Ryzen 7 3700X, using Docker 3.5.2.
As Dave mentioned in the video, the Java implementation uses a bool array. Looking at the code, it's also optimized as (what I call) an inverted bool array. That is, it starts the array off as all false instead of all true, since the system will automatically initialize the array to false when it's first created, and thus setting it to true doubles the array creation time.
It uses the standard 1 of 2 algorithm.
I'll compare it with my bool2 and ibool2 sieves.
Java:
C#:
Caveat: Values can vary by a few hundred points per run, particularly on the bool array which is going to generate a lot of memory pressure in the cache.
So the C# version is about 45% faster than the Java version. The basic bool version (as Dave didn't recognize that the Java was running an iBool implementation) is almost 30% faster.
Both of them are vastly higher than the numbers shown on Dave's video (where they were slightly above 2000), so there's likely a notable difference in hardware being used to test things, or maybe WSL vs WSL2.
Docker
Which brings us to the Docker situation. In particular, the numbers I see when running on Docker are vastly different from what I'm seeing in other discussions. In fact, I think when I first ran my own solution on Docker, I was getting lower numbers.
I know for certain that some things tank Docker performance (particularly multithreading). But my numbers are much higher than those shown in, say, the Results discussion.
Now, I know that seemingly minor things can significantly alter the results. For example, the choice between a while loop vs for loop has had some interesting results. Moreso in Docker.
With the bitarray, native code has for vs while nearly identical, at slightly above 3700. However in Docker, the for loop gives 2600, while the while loop gives 3000.
The bool array sieve under Docker goes from 9500 (for loop) to 8650 (while loop). With the inverted bool array, going from the for loop to the while loop drops it from 10200 to 9400.
Meanwhile under native, going from the for loop to the while loop increases the performance. The basic bool array increases from 9200 to 10400, and the inverted bool array increases from 9400 to 9900.
So I've got some concerns about how the performance is being measured, and also about how optimizations are impacting results in different environments.
Beta Was this translation helpful? Give feedback.
All reactions