This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients mark.dickinson, rhettinger, serhiy.storchaka
Date 2013-09-01.18:49:26
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1378061368.61.0.991913209917.issue18900@psf.upfronthosting.co.za>
In-reply-to
Content
In some functions in the random module checking input arguments and precomputation takes a considerable portion of time. Here is a sample implementation of new random.distrib module which provides alternative faster interface to generating of random distributed values. It contains generators which generates values with same distributions as functions with same name in the random module.

Benchmark results:

                                random distrib
random()                         0.061   0.055  1.12
randrange(0, 100, 5)             1.494   0.620  2.41
randint(1, 100)                  1.283   0.551  2.33
uniform(-10.0, 10.0)             0.332   0.121  2.73
triangular(0.0, 10.0, 6.0)       0.661   0.317  2.09
gauss(5.0, 2.0)                  0.707   0.280  2.53
normalvariate(5.0, 2.0)          0.867   0.553  1.57
lognormvariate(5.0, 2.0)         1.078   0.640  1.68
expovariate(0.1,)                0.508   0.293  1.73
vonmisesvariate(1.0, 1.0)        1.201   0.671  1.79
gammavariate(0.35, 1.45)         1.117   0.508  2.20
betavariate(2.71828, 3.14159)    2.868   1.776  1.61
paretovariate(5.0,)              0.493   0.238  2.07
weibullvariate(1.0, 3.0)         0.670   0.402  1.67
choice([0, 1, 2, 3, 4, 5, 6...   0.887   0.594  1.49

Distrib functions are 1.5-2.8 times faster than random functions. Weighted choice() function (see issue18844) can be even dozens times faster (depends on size of the input).

In additional some random generators (i.e. gauss()) looks simpler when implemented as generators. distrib.gauss() is twice faster than distrib.normalvariate() (both generates numbers with same distribution) and I think some other generators can be implemented more efficient in generator style.
History
Date User Action Args
2013-09-01 18:49:29serhiy.storchakasetrecipients: + serhiy.storchaka, rhettinger, mark.dickinson
2013-09-01 18:49:28serhiy.storchakasetmessageid: <1378061368.61.0.991913209917.issue18900@psf.upfronthosting.co.za>
2013-09-01 18:49:28serhiy.storchakalinkissue18900 messages
2013-09-01 18:49:28serhiy.storchakacreate