-
-
Notifications
You must be signed in to change notification settings - Fork 42
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
Performance #298
Comments
Thanks for mentioning that. We had some benchmarks very early on by @desruisseaux but I believe that is no longer there or vanished with the JSR 275 codebase. The better performance of primitive types is not new, but they are primitive and you would not want to sacrifice the data integrity or more as the Mars Climate Orbiter showed (although they may not use Java directly on the spacecraft;-) The performance penalty is known, although your example is not the best comparison, since you combine parsing/formatting with the most primitive numerical operations even using BigDecimal. However, you will always need more space to deal with quantities than primitive numbers. HTH, I don't think the snippet works as a real benchmark, but you are more than welcome to contribute to that, if you can. |
The result for 1.0 is
|
Not sure what you mean with "real benchmark", sure this is artificially to highlight the problem?! But the use case is to replace all numbers with quantities to assure correct calculation according to assigned units in a system where you do a lot of math and data manipulation. |
Did you use Apache stopwatch or what is the stopwatch? The parsing should not be used in one case only, instantiating a new Quantity with the Units constant seems more appropriate in this case. Do you have some code snippets including Apache Stopwatch we could try out? I created #299 for a true benchmark. |
Indriya 2.0.x does calculation with higher precision than 1.x. Also note, that you can speed up calculations above by being more careful when picking operand values for comparison. (might be 2 orders of magnitude faster) ... // instead of
BigDecimal b = new BigDecimal(5.2);
// use
BigDecimal b = new BigDecimal("5.2");
// instead of
Quantities.getQuantity(5.2, Units.METRE);
// use
Quantities.getQuantity(RationalNumber.of(52, 10), Units.METRE); |
Thanks for the input @andi-huber, could you maybe with help by @parnold-x if he wishes to help and others like @desruisseaux if he has time think about a benchmark along the lines of https://github.com/JavaMoney/javamoneyjmh? I forked that based on something a contributor did earlier. We don't have to use Gradle, since Maven is currently used everywhere else, but the idea would be to create some benchmarks that show also how using |
I've created a gist, not a best practice benchmark, but gives some idea on what to look for. Testing 3 aspects of quantity calculus:
https://gist.github.com/andi-huber/92ab34634560f22647adab584041144c Showing
Roughly speaking, Indriya is 20 times slower than when using BigDecimal directly. However, this sound pretty reasonable to me. |
I think if the JUnit test itself does not take too long, we could add it to the JUnit tests, if it is very slow, then it should be excluded like some LocalUnitFormat tests because they occasionally cause resource overflows during the whole build (something we might like to explore, but LocalUnitFormat is also not a core feature and mostly for GUI rendering, not unit exchange between systems) |
I added it under https://github.com/unitsofmeasurement/indriya/blob/master/src/test/java/tech/units/indriya/IndriyaPerformanceTest.java, with a few tweaks like log outputs instead of System.out. So it can be run with a custom logging properties while by default it won't pollute the regular builds. |
Hi, not sure if this is a issue for you but it seems that the 2.0 implementation is somehow not really performant. For the simple addition test below, I see these numbers in ms
The text was updated successfully, but these errors were encountered: