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

Improve performances of BigInteger.numberOfDecimalDigits(). #300

Merged
merged 1 commit into from
Jul 14, 2024

Conversation

glureau
Copy link
Contributor

@glureau glureau commented Jun 10, 2024

Similar PR than previous one but with focus on the BigInteger.

    @Test
    fun perfTest() {
        val bd = BigInteger.parseString("123")
        val duration = measureTime {
            repeat(1_000_000) { bd.numberOfDecimalDigits() }
        }
        println("Duration: $duration")
    }

Result (best of 3 runs)

platform Before After Time reduction
iosSimulator 4.60s 0.62s reduction of 86%
JVM 219ms 75.2ms reduction of 66%
macosArm64 4.91s 0.67ms reduction of 86%

All benchmark data

All runs are done on the same MacBook Pro M3 with 36GB RAM.

Before

  • ios 4.83, 4.60, 4.67
  • jvm 234ms, 219ms, 241ms
  • mac 4.92, 4.91, 4.98

After

  • ios 622ms, 617ms, 619ms
  • jvm 11.6ms, 9.8ms, 11.4ms
  • mac 673ms, 666ms, 666ms

Just a side note, I took a relatively short value for the benchmark, I guess performances may vary with length (like the previous implementation). I only run one more test on JVM with "123456789012345678901234567890123456", before 232ms, after 54ms, so I guess we're still in a better place.

@ionspin ionspin merged commit e32ae81 into ionspin:main Jul 14, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants