Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better Bf2 Java implementation. #173

Open
wants to merge 1 commit into
base: master
from

Conversation

@renatoathaydes
Copy link

commented Jun 29, 2019

This PR implements brainfuck2 in Java that runs much faster than the current implementation.

The code is still pretty clean and very readable, besides being more testable.

On my system, here are the figures I am getting comparing the new implementation with the current one, as well as with the Kotlin (current fastest in the project README) implementation:

  • in seconds
Java (current) Java (new) Kotlin
2.6 1.4 2.0

The Kotlin implementation is also not optimal, I will make a PR offering a faster implementation for it as well.

@renatoathaydes

This comment has been minimized.

Copy link
Author

commented Jun 29, 2019

I need to clarify that the times I posted above is when running Java 8 with the GraalVM's JIT.

On the Oracle JVM, there's a performance issue with the Java version, so it runs much slower than Kotlin.

Here's my data:

Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)

  • Java (new): first run and subsequent runs: 3.6 seconds
  • Java (current): first run: 4.3 seconds. Subsequent runs: 3.0 seconds
  • Kotlin: first run: 1.2 seconds. Subsequent runs: 1.55 seconds.

OpenJDK 64-Bit GraalVM CE 19.0.2 (build 25.212-b03-jvmci-19-b04, mixed mode)

  • Java (new): first run: 1.48 seconds. Subsequent runs: 1.43 seconds
  • Java (current): first run and subsequent runs: 2.5 seconds.
  • Kotlin: first run: 2.0 seconds. Subsequent runs: 1.96 seconds.

So, the performance depends a lot on which JIT is used for Java.

@renatoathaydes

This comment has been minimized.

Copy link
Author

commented Jun 29, 2019

For comparison, the Go implementation on my machine runs in about 2.0 seconds.

sebthom added a commit to sebthom/benchmarks that referenced this pull request Jul 26, 2019

Improve Java bf2
By doing some very simple changes to the existing Java implementation (using array instead of list, using final modifierers, avoiding Character/char autoboxing, reusing empty arrays) I can see a 100% performance improvement.
This version apparently also runs significantly faster than version offered via kostya#173
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.