On Monday, December 28, 2015 at 1:10:25 PM UTC-5, Stefan Karpinski wrote:
>
> I would recommend against using decimal floating-point unless you really 
> must. On almost any hardware you're likely to use, binary floating-point 
> arithmetic will be an order of magnitude faster than decimal floating-point 
> arithmetic. Moreover, if you use decimal floating-point, you will 
> chronically find yourself unable to use standard numerical libraries 
> without converting your data first.
>

True - I was not advocating using decimal floating point *unless* you must, 
however, there are a number of use cases where that you do need to use 
decimal floating point,
and you might find that using decimal floating point can actually be faster 
than using larger precision binary floating point if you are trying to 
avoid some of the conversion issues that exist with binary floating point. 
 For example, in some benchmarks I ran comparing `DecFP.jl` to `BigFloat`, 
DecFP was about 2-3 times faster than 256-bit BigFloat.
(DecFP is very nice, in that it uses bitstypes, but BigFloat causes a 
number of allocations for every operation - which may indicate that some 
work could be done on Julia's BigFloat wrapping, to use bitstypes, instead 
of having to have both an allocation for the type, and the array of words).

*julia> **f1() = (a = big"0.0" ; for i = 1:10000 ; a += big"0.1" ; end ; a)*

*f1 (generic function with 1 method)*


*julia> **f1()*

*9.999999999999999999999999999999999999999999999999999999999999999999999999859301e+02*


*julia> **f2() = (a = d"0.0" ; for i = 1:10000 ; a += d"0.1" ; end ; a)*

*f2 (generic function with 1 method)*


*julia> **f2()*

*+10000E-1*


*julia> **@benchmark f1()*

*================ Benchmark Results ========================*

*     Time per evaluation: 2.55 ms [139.77 μs, 4.95 ms]*

*Proportion of time in GC: 4.52% [0.00%, 16.41%]*

*        Memory allocated: 1015.63 kb*

*   Number of allocations: 30000 allocations*

*       Number of samples: 100*

*   Number of evaluations: 100*

* Time spent benchmarking: 0.31 s*



*julia> **@benchmark f2()*

*================ Benchmark Results ========================*

*     Time per evaluation: 792.35 μs [703.65 μs, 881.05 μs]*

*Proportion of time in GC: 0.00% [0.00%, 0.00%]*

*        Memory allocated: 0.00 bytes*

*   Number of allocations: 0 allocations*

*       Number of samples: 100*

*   Number of evaluations: 100*

* Time spent benchmarking: 0.10 s*


*julia> **f1m() = (a = big"0.0" ; for i = 1:10000 ; a *= big"0.1" ; end ; 
a)*

*f1m (generic function with 1 method)*


*julia> **f2m() = (a = d"0.0" ; for i = 1:10000 ; a *= d"0.1" ; end ; a)*

*f2m (generic function with 1 method)*


*julia> **@benchmark f1m()*

*================ Benchmark Results ========================*

*     Time per evaluation: 2.03 ms [0.00 ns, 4.06 ms]*

*Proportion of time in GC: 3.73% [0.00%, 14.73%]*

*        Memory allocated: 1015.63 kb*

*   Number of allocations: 30000 allocations*

*       Number of samples: 100*

*   Number of evaluations: 100*

* Time spent benchmarking: 0.23 s*


*julia> **@benchmark f2m()*

*================ Benchmark Results ========================*

*     Time per evaluation: 756.59 μs [678.94 μs, 834.24 μs]*

*Proportion of time in GC: 0.00% [0.00%, 0.00%]*

*        Memory allocated: 0.00 bytes*

*   Number of allocations: 0 allocations*

*       Number of samples: 100*

*   Number of evaluations: 100*

* Time spent benchmarking: 0.10 s*

Reply via email to