-
Notifications
You must be signed in to change notification settings - Fork 0
Performance compared to Java Types
Performance comparison with Java BigDecimal and double (primitive)
The purpose of this performance test is to measure how big is the penalty for using Decimal against BigDecimal, and how does it relate to primitives.
The short summary, out of many executions I have found that
Decimal takes 1.18 times longer than BigDecimal
Decimal takes 84.69 times longer than Double
If you are interested, read on…
Processor Name: Intel Core 2 Duo
Processor Speed: 2.4 GHz
Number Of Processors: 1
Total Number Of Cores: 2
L2 Cache: 3 MB
Memory: 4 GB
Bus Speed: 1.07 GHz
java.runtime.name : [Java™ SE Runtime Environment]
java.specification.version : [1.6]
java.version : [1.6.0_15]
java.runtime.version : [1.6.0_15-b03-226]
java.vm.vendor : [Apple Inc.]
java.vm.name : [Java HotSpot™ 64-Bit Server VM]
java.vm.version : [14.1-b02-92]
java.vm.specification.vendor : [Sun Microsystems Inc.]
java.vm.info : [mixed mode]
java.class.version : [50.0]
sun.arch.data.model : 64
sun.management.compiler : [HotSpot 64-Bit Server Compiler]
Operating system: [Mac OS X x86_64][10.5.8]
Available processors: 2
-mx=256 -mX=512
Summary:
| Class | Mean | Std. Deviation |
|---|---|---|
| Decimal | 1.599 μs | 1.083 μs |
| BigDecimal | 1.145 μs | 637.803 ns |
| Double | 23.314 ns | 7.223 ns |
Delta from Java types
| Decimal Delta | Mean | Std. Deviation |
|---|---|---|
| BigDecimal | 454.096 ns | 445.203 ns |
| Double | 1.576 μs | 1.076 μs |
Performing a System.gc() call and waiting for 2 seconds in between each test revealed that only in the case of division, the memory usage seems to increase, while performing almost 30% faster.
-mx=256 -mX=1024Summary:
| Class | Mean | Std. Deviation |
|---|---|---|
| Decimal | 1.095 μs | 309.101 ns |
| BigDecimal | 689.357 ns | 275.052 ns |
| Double | 15.613 ns | 6.013 ns |
Delta from Java types…
| Decimal delta | Mean | Std. Deviation |
|---|---|---|
| BigDecimal | 405.288 ns | 34.049 ns |
| Double | 1.079 μs | 303.088 ns |
Performance tests for Quantify: Sun Oct 04 14:47:44 BST 2009
Creating dataset with 1000000 random numbers:
Finished creating data, sleeping…
Ready to start!
BigDecimal operation: Plus
613.063 ns
Memory allocated: 277.545 mb
Memory free: 50.892 mb
Delta: 226.653 mb
BigDecimal operation: Minus
599.455 ns
Memory allocated: 399.286 mb
Memory free: 105.216 mb
Delta: 294.071 mb
BigDecimal operation: Multiply:
1.143 μs
Memory allocated: 399.286 mb
Memory free: 10.181 mb
Delta: 389.105 mb
BigDecimal operation: Divide:
401.713 ns
Memory allocated: 542.429 mb
Memory free: 153.543 mb
Delta: 388.886 mb
Decimal operation: Plus:
762.157 ns
Memory allocated: 542.429 mb
Memory free: 223.206 mb
Delta: 319.223 mb
Decimal operation: Minus:
833.229 ns
Memory allocated: 542.429 mb
Memory free: 189.769 mb
Delta: 352.660 mb
Decimal operation: Times:
1.508 μs
Memory allocated: 542.429 mb
Memory free: 110.508 mb
Delta: 431.921 mb
Decimal operation: By:
1.276 μs
Memory allocated: 585.196 mb
Memory free: 154.888 mb
Delta: 430.308 mb
Double operation: Plus:
14.358 ns
Memory allocated: 585.196 mb
Memory free: 319.853 mb
Delta: 265.343 mb
Double operation: Minus:
10.852 ns
Memory allocated: 585.196 mb
Memory free: 392.076 mb
Delta: 193.119 mb
Double operation: Times:
11.471 ns
Memory allocated: 585.196 mb
Memory free: 392.223 mb
Delta: 192.972 mb
Double operation: divide:
25.772 ns
Memory allocated: 585.196 mb
Memory free: 392.320 mb
Delta: 192.875 mb
Summary:
| Class | Mean | Std. Deviation |
|---|---|---|
| Decimal | 1.260 μs | 331.063 ns |
| BigDecimal | 730.944 ns | 318.733 ns |
| Double | 24.010 ns | 11.663 ns |
Delta from Java types…
| Decimal diff | Mean | Std. Deviation |
|---|---|---|
| BigDecimal | 528.698 ns | 12.330 ns |
| Double | 1.236 μs | 319.399 ns |
Performance tests for Quantify: Sun Oct 04 22:48:38 BST 2009
Creating dataset with 1000000 random numbers:
Finished creating data, sleeping 15 seconds…
System load average: 55.57%
Ready to start!
BigDecimal operation: Add:
Execution finished in 629.410 ns
Memory allocated: 316.314 mb
Memory free: 93.962 mb
Delta: 222.352 mb
BigDecimal operation: Subtract:
Execution finished in 530.287 ns
Memory allocated: 316.314 mb
Memory free: 29.307 mb
Delta: 287.006 mb
BigDecimal operation: Multiply:
Execution finished in 1.276 μs
Memory allocated: 423.662 mb
Memory free: 13.303 mb
Delta: 410.358 mb
BigDecimal operation: Divide:
Execution finished in 488.257 ns
Memory allocated: 469.275 mb
Memory free: 7.888 mb
Delta: 461.387 mb
Decimal operation: Plus:
Execution finished in 923.894 ns
Memory allocated: 545.755 mb
Memory free: 15.403 mb
Delta: 530.352 mb
Decimal operation: Minus:
Execution finished in 947.733 ns
Memory allocated: 615.944 mb
Memory free: 4.688 mb
Delta: 611.256 mb
Decimal operation: Times:
Execution finished in 1.680 μs
Memory allocated: 783.061 mb
Memory free: 26.437 mb
Delta: 756.624 mb
Decimal operation: By:
Execution finished in 1.487 μs
Memory allocated: 855.806 mb
Memory free: 20.755 mb
Delta: 835.051 mb
Double operation: Plus:
Execution finished in 10.895 ns
Memory allocated: 855.806 mb
Memory free: 20.755 mb
Delta: 835.051 mb
Double operation: Minus:
Execution finished in 26.570 ns
Memory allocated: 855.806 mb
Memory free: 20.755 mb
Delta: 835.051 mb
Double operation: Times:
Execution finished in 16.839 ns
Memory allocated: 855.806 mb
Memory free: 20.755 mb
Delta: 835.051 mb
Double operation: Divide:
Execution finished in 41.734 ns
Memory allocated: 855.806 mb
Memory free: 20.755 mb
Delta: 835.051 mb
System load average: 77.69%
Execution finished in 8.120 s
Summary:
| Class | Mean | Std. Deviation |
|---|---|---|
| Decimal | 233.683 ns | 98.245 ns |
| BigDecimal | 154.565 ns | 44.101 ns |
| Double | 2.658 ns | 0.095 ns |
Delta from Java types…
| Decimal diff | Mean | Std. Deviation |
|---|---|---|
| BigDecimal | 79.118 ns | 54.144 ns |
| Double | 231.025 ns | 98.150 ns |
Decimal takes 1.51 times longer than BigDecimal
Decimal takes 87.91 times longer than Double
System load average: 39.06%
Execution finished in 1.637 s
Performance tests for Quantify: Sun Oct 04 23:32:02 BST 2009
Creating dataset with 1000000 random numbers:
Finished creating data, sleeping 15 seconds…
System load average: 39.06%
Ready to start!
BigDecimal operation: Add:
Execution finished in 151.630 ns
BigDecimal operation: Subtract:
Execution finished in 140.417 ns
BigDecimal operation: Multiply:
Execution finished in 224.036 ns
BigDecimal operation: Divide:
Execution finished in 102.177 ns
Decimal operation: Plus:
Execution finished in 141.804 ns
Decimal operation: Minus:
Execution finished in 169.173 ns
Decimal operation: Times:
Execution finished in 228.883 ns
Decimal operation: By:
Execution finished in 394.872 ns
Double operation: Plus:
Execution finished in 2.612 ns
Double operation: Minus:
Execution finished in 2.724 ns
Double operation: Times:
Execution finished in 2.527 ns
Double operation: Divide:
Execution finished in 2.770 ns