Re: random() (was Re: New GUC to sample log queries)

From: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Adrien Nayrat <adrien(dot)nayrat(at)anayrat(dot)info>, Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>, Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Tomas Vondra <tomas(dot)vondra(at)2ndquadrant(dot)com>, vik(dot)fearing(at)2ndquadrant(dot)com, Robert Haas <robertmhaas(at)gmail(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, David Rowley <david(dot)rowley(at)2ndquadrant(dot)com>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: random() (was Re: New GUC to sample log queries)
Date: 2018-12-28 08:44:05
Message-ID: alpine.DEB.2.21.1812280936010.32444@lancre
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


> About costs, not counting array accesses:
>
> - lrand48 (48 bits state as 3 uint16) is 29 ops
> (10 =, 8 *, 7 +, 4 >>)
> - xorshift+ (128 bits state as 2 uint64) is 13 ops
> ( 5 =, 0 *, 1 +, 3 >>, 4 ^)
> - xororshift128+ (idem) is 17 ops
> ( 6 =, 0 *, 1 +, 5 >>, 3 ^, 2 |, less if rot in hardware)
> - WELL512 (512 bits state as 16 uint32) is 38 ops
> (11 =, 0 *, 3 +, 7 >>, 10 ^, 4 &)
> probably much better, but probably slower than the current version
>
> I'd be of the (debatable) opinion that we could use xororshift128+, already
> used by various languages, even if it fails some specialized tests.

After some more digging, the better choice seems to be the 64 bits
optimized xoshiro256** (xoshiro = xor shift rotate):

- xoshiro256** (256 bits states as 4 uint64) is 24 ops (18 if rot in hw)
8 =, 2 *, 2 +, 5 <<, 5 ^, 2 |

See http://vigna.di.unimi.it/xorshift/

--
Fabien.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Mitar 2018-12-28 08:48:46 Re: Feature: triggers on materialized views
Previous Message Masahiko Sawada 2018-12-28 08:31:44 Re: Allow CLUSTER, VACUUM FULL and REINDEX to change tablespace on the fly