mlangc commented on PR #140:
URL: https://github.com/apache/commons-numbers/pull/140#issuecomment-1972901325

   After adding some benchmarks, I found out that the existing GCD 
implementation for ints is also very performant for longs, if only [one small 
change is made to 
it](https://github.com/apache/commons-numbers/pull/140/files#diff-bc43c3c529c46031a270abcd8086d9f155836cb9efc1aef3bd96cfffe37dcadbL95).
 Thus I adapted the implementation for ints, and replaced the version for longs 
with the same code, but for 64 bits.
   
   Here are the benchmark results in 1000 GCDs per second (see 
https://github.com/apache/commons-numbers/pull/140/files#diff-61d1811860900830accad2a21d17e8bcd905486d5c91ed6e43bef31e11e27147):
   ```
   Benchmark                                Mode  Cnt      Score      Error  
Units
   GcdPerformance.gcdBigInteger            thrpt   10   1504.116 ±  166.441  
ops/s
   GcdPerformance.gcdInt                   thrpt   10  21050.470 ± 1057.856  
ops/s
   GcdPerformance.gcdLong                  thrpt   10  10352.825 ±  272.360  
ops/s
   GcdPerformance.oldGcdInt                thrpt   10  21003.386 ±  849.209  
ops/s
   GcdPerformance.oldGcdIntAdaptedForLong  thrpt   10   4741.043 ±  562.422  
ops/s
   GcdPerformance.oldGcdLong               thrpt   10   2500.723 ±   79.173  
ops/s
   ```
   
   As you can see, the performance for ints is not really affected by the 
change, however for longs, there is a big difference, as you can see here (see 
https://colab.research.google.com/drive/11uz20qhFhUgv_-2YewzR--SDRD4_swYr#scrollTo=1M4k9mlEbvab&line=32&uniqifier=1)
   
![gcd-long-performance](https://github.com/apache/commons-numbers/assets/7326646/8248ecba-6fc7-46a6-b68b-cd6aa79ab2b8)
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to