IcoreE opened a new pull request, #1526:
URL: https://github.com/apache/commons-lang/pull/1526

   Hello @garydgregory
   I have submitted a **new PR** that addresses this
   - Full unit tests are included, and a comparison of two hashCode algorithms 
(Objects.hash vs. bitwise operations) is added with both contract validation 
and performance benchmarks.
   
   I’ve conducted a detailed performa hashCode implementations for the 
CharRange class (package: org.apache.commons.lang3) and wanted to share the 
results:
   **1. Test Overview**
   I benchmarked two hashCode implementations for CharRange 
(coreorg.apache.commons.lang3.CharRange class):
   Baseline: hashCodeObjects() (using Objects.hash(end, negated, start) – 
standard general-purpose implementat
   Optimized: hashCodeBitwise() (bitwise splicing of startendnegated
   **2. Key Test Results (100 million iterations/scenario)**
   
   ===== CharRange hashCode Efficiency Comparison (Execution count: 100000000 
iterations/scenario) =====
   ```
   Total time for Objects.hash version: 5139 ms, accumulated result: 
6360454000000000
   Total time for bitwise operation version: 94 ms, accumulated result: 
1087927400000000
   Efficiency improvement of bitwise version over Objects.hash version: 98.17%
   ```
   The bitwise implementation achieves a 98.17% reduction in execution time 
compared to the Objects.hash
   
   **3. Why the Bitwise Version is Superior**
   
   1. Extreme efficiency: Uses only 3 native bitwise operations (left shift, 
bitwise OR, XOR) – no temporary array allocation, autoboxing, loops, or 
multiplication (all sources of overhead in Objects.hash)
   2. Contract compliance: Strictly adheres to Java’s hashCode/equals rules 
(equal instances have identical hashes; unequal instances rarely collide).
   3. Memory-friendly: No GC overhead (unlike Objects.hash, which creates 
temporary Object[] arrays).  


-- 
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