You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by "Evgeniya Maenkova (JIRA)" <ji...@apache.org> on 2007/01/30 16:13:33 UTC

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

[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
         Attachments: 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.


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

Posted by "Alexey Petrenko (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HARMONY-3088?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Alexey Petrenko resolved HARMONY-3088.
--------------------------------------

    Resolution: Fixed

The patch has been applied, please verify.

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


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

Posted by "Alexey Varlamov (JIRA)" <ji...@apache.org>.
    [ 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.


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

Posted by "Alexey Petrenko (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HARMONY-3088?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Alexey Petrenko reassigned HARMONY-3088:
----------------------------------------

    Assignee: Alexey Petrenko

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


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

Posted by "Evgeniya Maenkova (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-3088?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12469370 ] 

Evgeniya Maenkova commented on HARMONY-3088:
--------------------------------------------

License granted to ASF for inclusion in ASF works (as per the Apache Software License ยง5).


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


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

Posted by "Evgeniya Maenkova (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HARMONY-3088?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Evgeniya Maenkova updated HARMONY-3088:
---------------------------------------

    Attachment: math.equals.patch

BigDecimal/BigInteger patch

> [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
>         Attachments: 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.


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

Posted by "Alexey Petrenko (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-3088?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12469392 ] 

Alexey Petrenko commented on HARMONY-3088:
------------------------------------------

I agree with Evgeniya.

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


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

Posted by "Evgeniya Maenkova (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-3088?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12469738 ] 

Evgeniya Maenkova commented on HARMONY-3088:
--------------------------------------------

Thanks, Alexey: works fine.

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


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

Posted by "Evgeniya Maenkova (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HARMONY-3088?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Evgeniya Maenkova closed HARMONY-3088.
--------------------------------------


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


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

Posted by "Evgeniya Maenkova (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HARMONY-3088?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Evgeniya Maenkova updated HARMONY-3088:
---------------------------------------

    Attachment: Equals.java

test case mentioned in the description

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


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

Posted by "Evgeniya Maenkova (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-3088?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12469375 ] 

Evgeniya Maenkova commented on HARMONY-3088:
--------------------------------------------

Alexey, as this check is pretty cheap and we cannot define exactly distribution of this comparing in the real life applications, I belive it makes sense.

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