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 11:07:30
Message-ID: alpine.DEB.2.21.1812281149090.32444@lancre
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


>> - lrand48 (48 bits state as 3 uint16) is 29 ops
>> (10 =, 8 *, 7 +, 4 >>)
>
> - 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/

Small benchmark on my laptop with gcc-7.3 -O3:

- pg_lrand48 takes 4.0 seconds to generate 1 billion 32-bit ints

- xoshiro256** takes 1.6 seconds to generate 1 billion 64-bit ints

With -O2 it is 4.8 and 3.4 seconds, respectively. So significantly better
speed _and_ quality are quite achievable.

Note that small attempt at optimizing these functions (inline constants,
array replaced with scalars) did not yield significant improvements.

--
Fabien.

Attachment Content-Type Size
test_pg_erand48.c text/x-csrc 1.6 KB
test_xoroshi256ss.c text/x-csrc 740 bytes

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2018-12-28 11:08:43 Re: could recovery_target_timeline=latest be the default in standby mode?
Previous Message Magnus Hagander 2018-12-28 09:12:24 Re: Offline enabling/disabling of data checksums