summaryrefslogtreecommitdiff
path: root/doc/source/reference/random/performance.rst
blob: 395744eb8afd1287cfa11b8786e6929ce90222e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
Performance
-----------

.. py:module:: numpy.random

.. currentmodule:: numpy.random

Recommendation
**************
The recommended generator for single use is
:class:`~.xoshiro256.Xoshiro256`.  The recommended generator
for use in large-scale parallel applications is
:class:`~.xoshiro512.Xoshiro512` where the `jumped` method is used to advance
the state. For very large scale applications -- requiring 1,000+ independent
streams -- :class:`~.philox.Philox` is the best choice.

Timings
*******

The timings below are the time in ns to produce 1 random value from a
specific distribution.  The original :class:`~mt19937.MT19937` generator is
much slower since it requires 2 32-bit values to equal the output of the
faster generators.

Integer performance has a similar ordering although `dSFMT` is slower since
it generates 53-bit floating point values rather than integer values.

The pattern is similar for other, more complex generators. The normal
performance of NumPy's MT19937 is much lower than the other since it
uses the Box-Muller transformation rather than the Ziggurat generator. The
performance gap for Exponentials is also large due to the cost of computing
the log function to invert the CDF.

.. csv-table::
    :header: ,Xoshiro256**,Xoshiro512**,DSFMT,MT19937,Philox,NumPy,ThreeFry
    :widths: 14,14,14,14,14,14,14,14

    32-bit Unsigned Ints,2.6,2.9,3.4,3.2,5.0,3.3,7.6
    64-bit Unsigned Ints,3.1,4.0,5.6,5.7,6.6,8.1,13.4
    Uniforms,3.7,4.2,3.2,7.4,9.1,8.9,13.5
    Exponentials,4.3,5.3,7.3,8.2,9.7,42.4,14.9
    Normals,8.2,8.9,11.7,13.4,15.0,37.3,18.6
    Binomials,20.0,20.8,19.8,26.4,28.2,26.6,31.0
    Gammas,26.4,28.7,30.4,37.1,38.8,62.9,49.0
    Laplaces,40.2,40.0,39.4,48.7,51.2,47.4,51.4
    Poissons,48.8,51.6,47.8,73.6,82.3,74.0,90.6


The next table presents the performance in percentage relative to values
generated by the legagy generator, `RandomState(MT19937())`. The overall
performance was computed using a geometric mean.

.. csv-table::
    :header: ,Xoshiro256**,Xoshiro512**,DSFMT,MT19937,Philox,ThreeFry
    :widths: 14,14,14,14,14,14,14
    
    32-bit Unsigned Ints,129,113,98,103,66,44
    64-bit Unsigned Ints,258,202,145,142,122,61
    Uniforms,244,214,283,121,98,66
    Exponentials,981,796,580,518,436,285
    Normals,453,417,319,278,249,200
    Binomials,133,128,134,101,94,86
    Gammas,238,219,207,170,162,129
    Laplaces,118,118,120,97,93,92
    Poissons,152,144,155,101,90,82
    Overall,233,209,194,152,130,98

.. note::

   All timings were taken using Linux on a i5-3570 processor.