bb.util
Class NumberUtil.UnitTest

java.lang.Object
  extended by bb.util.NumberUtil.UnitTest
Enclosing class:
NumberUtil

public static class NumberUtil.UnitTest
extends Object

See the Overview page of the project's javadocs for a general description of this unit test class.


Constructor Summary
NumberUtil.UnitTest()
           
 
Method Summary
 void benchmark_bytesXXXToLong()
          Results on 2009-03-16 (2.5 GHz Xeon E5420 desktop, jdk 1.6.0_11 server jvm): bytesBigEndianToLong: first = 445.636 ns, mean = 12.820 ns (CI deltas: -10.711 ps, +11.883 ps), sd = 513.376 ns (CI deltas: -84.393 ns, +127.359 ns) WARNING: execution times have mild outliers, SD VALUES MAY BE INACCURATE bytesBigEndianToLongSunAlgorithm: first = 318.513 ns, mean = 15.189 ns (CI deltas: -3.910 ps, +4.265 ps), sd = 132.630 ns (CI deltas: -19.080 ns, +28.666 ns) WARNING: execution times have mild outliers, SD VALUES MAY BE INACCURATE
 void benchmark_parseDouble()
          Results on 2009-03-16 (2.5 GHz Xeon E5420 desktop, jdk 1.6.0_11 server jvm): parseDouble: first = 9.112 us, mean = 105.897 ns (CI deltas: -85.813 ps, +87.547 ps), sd = 1.107 us (CI deltas: -142.445 ns, +177.904 ns) WARNING: SD VALUES MAY BE INACCURATE Double.parseDouble: first = 6.485 us, mean = 163.888 ns (CI deltas: -88.143 ps, +93.370 ps), sd = 1.163 us (CI deltas: -153.990 ns, +194.557 ns) WARNING: SD VALUES MAY BE INACCURATE So my code is somewhat faster than Sun's.
 void benchmark_parseInt()
          Results on 2009-03-16 (2.5 GHz Xeon E5420 desktop, jdk 1.6.0_11 server jvm): parseInt: first = 4.538 us, mean = 40.102 ns (CI deltas: -33.837 ps, +32.933 ps), sd = 811.540 ns (CI deltas: -116.909 ns, +146.693 ns) WARNING: SD VALUES MAY BE INACCURATE Integer.parseInt: first = 5.191 us, mean = 60.732 ns (CI deltas: -40.983 ps, +42.931 ps), sd = 720.814 ns (CI deltas: -110.752 ns, +172.153 ns) WARNING: execution times have mild outliers, SD VALUES MAY BE INACCURATE So my code is somewhat faster than Sun's.
 void benchmark_parseLong()
          Results on 2009-03-16 (2.5 GHz Xeon E5420 desktop, jdk 1.6.0_11 server jvm): parseLong: first = 3.153 us, mean = 70.039 ns (CI deltas: -54.772 ps, +44.126 ps), sd = 863.480 ns (CI deltas: -205.259 ns, +446.310 ns) WARNING: EXECUTION TIMES HAVE EXTREME OUTLIERS, SD VALUES MAY BE INACCURATE Long.parseLong: first = 2.082 us, mean = 172.169 ns (CI deltas: -222.372 ps, +310.273 ps), sd = 3.245 us (CI deltas: -764.768 ns, +1.215 us) WARNING: EXECUTION TIMES HAVE EXTREME OUTLIERS, SD VALUES MAY BE INACCURATE So my code is much faster than Sun's.
private  long bytesBigEndianToLongSunAlgorithm(byte[] bytes)
           
 void find_magnitudeExactMax()
          This method finds the maximum power of 10 which can be represented with no loss of precision by a double.
 void find_maxMantissaDigits()
           
private static String generateDoubleText(Random random)
           
private  void parseIntCheck(int i)
           
 void test_bytesXXXToLong()
           
 void test_getMillValue()
           
 void test_parseDouble()
           
 void test_parseInt_fail1()
           
 void test_parseInt_fail2()
           
 void test_parseInt_pass1()
           
 void test_parseInt_pass2()
           
 void test_parseLong_fail1()
           
 void test_parseLong_fail2()
           
 void test_parseLong_pass()
           
 void test_scientificNotationFormat()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NumberUtil.UnitTest

public NumberUtil.UnitTest()
Method Detail

find_maxMantissaDigits

public void find_maxMantissaDigits()

find_magnitudeExactMax

public void find_magnitudeExactMax()
This method finds the maximum power of 10 which can be represented with no loss of precision by a double. Comment on the algorithm below: since 10 = 5*2 we can instead simply find the maximum power of 5 which can be represented with no loss of precision by a double, since as multiply 10s together, the factors of 2 can all be perfectly absorbed into the double's (power of 2) exponent.


test_bytesXXXToLong

public void test_bytesXXXToLong()

benchmark_bytesXXXToLong

public void benchmark_bytesXXXToLong()
Results on 2009-03-16 (2.5 GHz Xeon E5420 desktop, jdk 1.6.0_11 server jvm):

                        bytesBigEndianToLong: first = 445.636 ns, mean = 12.820 ns (CI deltas: -10.711 ps, +11.883 ps), sd = 513.376 ns (CI deltas: -84.393 ns, +127.359 ns) WARNING: execution times have mild outliers, SD VALUES MAY BE INACCURATE
                        bytesBigEndianToLongSunAlgorithm: first = 318.513 ns, mean = 15.189 ns (CI deltas: -3.910 ps, +4.265 ps), sd = 132.630 ns (CI deltas: -19.080 ns, +28.666 ns) WARNING: execution times have mild outliers, SD VALUES MAY BE INACCURATE
 


bytesBigEndianToLongSunAlgorithm

private long bytesBigEndianToLongSunAlgorithm(byte[] bytes)
                                       throws IllegalArgumentException
Throws:
IllegalArgumentException

test_getMillValue

public void test_getMillValue()

test_scientificNotationFormat

public void test_scientificNotationFormat()
                                   throws ParseException
Throws:
ParseException

test_parseDouble

public void test_parseDouble()

generateDoubleText

private static String generateDoubleText(Random random)

benchmark_parseDouble

public void benchmark_parseDouble()
Results on 2009-03-16 (2.5 GHz Xeon E5420 desktop, jdk 1.6.0_11 server jvm):

                        parseDouble: first = 9.112 us, mean = 105.897 ns (CI deltas: -85.813 ps, +87.547 ps), sd = 1.107 us (CI deltas: -142.445 ns, +177.904 ns) WARNING: SD VALUES MAY BE INACCURATE
                        Double.parseDouble: first = 6.485 us, mean = 163.888 ns (CI deltas: -88.143 ps, +93.370 ps), sd = 1.163 us (CI deltas: -153.990 ns, +194.557 ns) WARNING: SD VALUES MAY BE INACCURATE
 
So my code is somewhat faster than Sun's.


test_parseInt_pass1

public void test_parseInt_pass1()

parseIntCheck

private void parseIntCheck(int i)

test_parseInt_pass2

public void test_parseInt_pass2()

test_parseInt_fail1

public void test_parseInt_fail1()

test_parseInt_fail2

public void test_parseInt_fail2()

benchmark_parseInt

public void benchmark_parseInt()
Results on 2009-03-16 (2.5 GHz Xeon E5420 desktop, jdk 1.6.0_11 server jvm):

                        parseInt: first = 4.538 us, mean = 40.102 ns (CI deltas: -33.837 ps, +32.933 ps), sd = 811.540 ns (CI deltas: -116.909 ns, +146.693 ns) WARNING: SD VALUES MAY BE INACCURATE
                        Integer.parseInt: first = 5.191 us, mean = 60.732 ns (CI deltas: -40.983 ps, +42.931 ps), sd = 720.814 ns (CI deltas: -110.752 ns, +172.153 ns) WARNING: execution times have mild outliers, SD VALUES MAY BE INACCURATE
 
So my code is somewhat faster than Sun's.


test_parseLong_pass

public void test_parseLong_pass()

test_parseLong_fail1

public void test_parseLong_fail1()

test_parseLong_fail2

public void test_parseLong_fail2()

benchmark_parseLong

public void benchmark_parseLong()
                         throws Exception
Results on 2009-03-16 (2.5 GHz Xeon E5420 desktop, jdk 1.6.0_11 server jvm):

                        parseLong: first = 3.153 us, mean = 70.039 ns (CI deltas: -54.772 ps, +44.126 ps), sd = 863.480 ns (CI deltas: -205.259 ns, +446.310 ns) WARNING: EXECUTION TIMES HAVE EXTREME OUTLIERS, SD VALUES MAY BE INACCURATE
                        Long.parseLong: first = 2.082 us, mean = 172.169 ns (CI deltas: -222.372 ps, +310.273 ps), sd = 3.245 us (CI deltas: -764.768 ns, +1.215 us) WARNING: EXECUTION TIMES HAVE EXTREME OUTLIERS, SD VALUES MAY BE INACCURATE
 
So my code is much faster than Sun's.

Throws:
Exception