-
-
Notifications
You must be signed in to change notification settings - Fork 818
Faster division by 1000 #1203
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
Merged
Merged
Faster division by 1000 #1203
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
09a30f0
floating point multiplication in integer domain
antonin-janec 86f8ab3
integer division by 1000 via multiply and shift
antonin-janec bcced46
test for multiplication by 0.80 in integer domain
antonin-janec 6a2ea3b
bugfix for integer division by 1000
antonin-janec a4840c2
bugfix for multiplication by 0.80 in integer domain
antonin-janec ec03a5f
Speed up manual test by avoiding String concatenation for non-failing…
cowtowncoder 202df72
Improve unit test a bit to allow partial check to always run; leave f…
cowtowncoder d230d2e
Add release notes
cowtowncoder c31c811
Merge branch '2.17' into FAST_DIVISION
cowtowncoder f3e01de
Convert new test to JUnit5
cowtowncoder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/test/java/com/fasterxml/jackson/core/io/NumberOutputTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| package com.fasterxml.jackson.core.io; | ||
|
|
||
| import org.junit.jupiter.api.Disabled; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.fail; | ||
|
|
||
| public class NumberOutputTest | ||
| { | ||
| @Test | ||
| public void testDivBy1000Small() | ||
| { | ||
| for (int number = 0; number <= 999_999; ++number) { | ||
| int expected = number / 1000; | ||
| int actual = NumberOutput.divBy1000(number); | ||
xtonik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (expected != actual) { // only construct String if fail | ||
| fail("With "+number+" should get "+expected+", got: "+actual); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testDivBy1000Sampled() | ||
| { | ||
| for (int number = 1_000_000; number > 0; number += 7) { | ||
| int expected = number / 1000; | ||
| int actual = NumberOutput.divBy1000(number); | ||
| if (expected != actual) { // only construct String if fail | ||
| fail("With "+number+" should get "+expected+", got: "+actual); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // And then full range, not included in CI since code shouldn't change; | ||
| // but has been run to verify full range manually | ||
| @Test | ||
| // Comment out for manual testing: | ||
| @Disabled | ||
| public void testDivBy1000FullRange() { | ||
| for (int number = 0; number <= Integer.MAX_VALUE; ++number) { | ||
| int expected = number / 1000; | ||
| int actual = NumberOutput.divBy1000(number); | ||
| if (expected != actual) { // only construct String if fail | ||
| fail("With "+number+" should get "+expected+", got: "+actual); | ||
| } | ||
| } | ||
| } | ||
| } | ||
19 changes: 19 additions & 0 deletions
19
src/test/java/com/fasterxml/jackson/core/sym/ByteQuadsCanonicalizerTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package com.fasterxml.jackson.core.sym; | ||
|
|
||
| import org.junit.Ignore; | ||
| import org.junit.Test; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
|
|
||
| public class ByteQuadsCanonicalizerTest { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's drop this test, along with optimization. |
||
| @Test | ||
| @Ignore | ||
| public void testMultiplyByFourFifths() { | ||
| for (long i = 0; i <= Integer.MAX_VALUE; i++) { | ||
| int number = (int) i; | ||
| int expected = (int) (number * 0.80); | ||
| int actual = ByteQuadsCanonicalizer.multiplyByFourFifths(number); | ||
xtonik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| assertEquals("input=" + number, expected, actual); | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.