PHPUnit Successful Conversion! [Beta]

We are pleased to announce that the first working version of PHPUnit has been converted using the RuntimeConverter, The project used for testing was the EmailTest shown on the PHPUnit getting started page (https://phpunit.de/getting-started/phpunit-7.html). While we know that PHPUnit has more features than this one test, we also know that this is a very significant milestone.

PHPUnit makes use of over 582 code files and uses a wide range of PHP language features, including several sub-projects. Just getting PHPUnit to compile was a large task, but it didn't prove anything. Getting it to run and give the same output as PHP over such a large framework (even if only a few tests have been done so far) really proves the viability of the RuntimeConverter for such enormous conversion tasks.

The code has been made available on GitHub for review [pending release of latest library, you can also run this code yourself] at https://github.com/RuntimeConverter/PHPUnit-Java-Converted.

Since PHPUnit is a large framework, here is a selected link to the converted contents of the "PHPUnit/Framework/Constraint" namespace (link). The "Constraint" classes refer to various expectations that can be placed on a test. You can see there the conversion of namespaces to packages, the resolution of functions and static functions, the resolution of class inheritance, package imports, comparison operators, and method calls!

This is the output of both the PHP and the Java programs:

--------------------

PHPUnit 7.1.4 by Sebastian Bergmann and contributors.

... 3 / 3 (100%)

Time: 24 ms, Memory: 2.00MB

OK (3 tests, 3 assertions)

--------------------

There is one significant difference in the run times printed by PHPUnit. Interestingly, the Runtime Converter gives us a rare chance to compare languages 1-1 (sort of). At first run, the Java program gives about 242 ms, vs 10ms on the PHP. That would be about 24x slower. Not great, but understandable given what the Runtime Library is doing behind the scenes to use dynamic features and embedded functions.

When the Java program is run 100 times in a loop, however, the run time drops to 24ms. Thats only 2.4x slower, and that is without any of a large number of optimizations that could be done to the generated code and passing 625 calls to the embedded system. If those embedded calls are replaced with native Java calls (done automatically after they are developed), then it is hard to see how the PHP time can't be equaled or beat by the Java code right out of the converter.

The reason for the difference is simple. On the first run, the Java classloader adds about 220ms to the run time. After that, the java HotSpot JIT compiler optimizes methods which were frequently called and reduces the time even further. Even though there were only 100 iterations of the program, many individual methods would be called thousands of times and trigger optimization.

The performance of the code, however, isn't the main point - now you can convert your "Email"

(src/main/java/com/project/convertedCode/globalNamespace/classes/Email.java)

class from loosely typed PHP into Java, and run your EmailTest

(src/main/java/com/project/convertedCode/globalNamespace/classes/EmailTest.java)

to verify the conversion.

Featured Posts
Recent Posts
Archive
Search By Tags
Follow Us
  • Facebook Basic Square
  • Twitter Basic Square
  • Google+ Basic Square

© 2017 RuntimeConverter