You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by "Alexey Varlamov (JIRA)" <ji...@apache.org> on 2007/01/31 07:58:05 UTC

[jira] Commented: (HARMONY-3088) [math]java.math.BigDecimal/java.math.BigInteger.equals improvement

    [ https://issues.apache.org/jira/browse/HARMONY-3088?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12468909 ] 

Alexey Varlamov commented on HARMONY-3088:
------------------------------------------

Re: 3) add primititve comparing at the beginning of equals methods (I mean if objects are the same). 
Practically this is pointless, it only works if workloads really compare the same objects often (and I hardly believe it is ever true for numbers). Otherwise it just adds extra instructions to executon path, and may even impede JIT to optimize.

> [math]java.math.BigDecimal/java.math.BigInteger.equals improvement
> ------------------------------------------------------------------
>
>                 Key: HARMONY-3088
>                 URL: https://issues.apache.org/jira/browse/HARMONY-3088
>             Project: Harmony
>          Issue Type: Improvement
>          Components: Classlib
>            Reporter: Evgeniya Maenkova
>         Assigned To: Alexey Petrenko
>         Attachments: Equals.java, math.equals.patch
>
>
> BigDecimal.equals/BigInteger.equals can be implemented more effectively, if:
> 1) in BigInteger: split equals and compareTo operations (equls implemented by compareTo now);
> 2) remove redudant type cast in BigDecimal;
> 3) add primititve comparing at the beginning of equals methods (I mean if objects are the same).
> I've written minimal test case and see this impovement in terms of time:
> current java.math:~44 sec;
> patched java.math:~18 sec.
> (I used my laptop so it's pretty approximately). 
> Test mentioned above is (also to be attached):
> import java.math.BigDecimal;
> public class Equals {
>     public static void main(String[] args) {
> 		BigDecimal[] values = new BigDecimal[100000];		
> 		for (int i = 0; i < values.length; i ++) {
> 			String s = i + "000" + i + "222" + i + "333." + i + "444";
> 			values[i] = new BigDecimal(s);
> 		}
> 		
> 		long start = System.currentTimeMillis();
> 		for (int i = 0; i < 1000; i ++) {
> 			for (int j = 0; j < values.length; j ++) {
> 				values[j].equals(values.length - j - 1);
> 				values[j].equals(values[j]);
> 			}
> 		}		
> 		
> 		System.out.println(System.currentTimeMillis() - start);
> 	}
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.