🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.c
Article #310030

Re: Optymalizacja kodu

#310030
From: M.M.
Date: Fri, 27 Dec 2019 07:44
169 lines
8068 bytes
On Thursday, December 26, 2019 at 9:57:09 AM UTC+1, Wojciech Muła wrote:
> Sprawdź, jak się sprawuje ten algorytm https://lemire.me/blog/2019/07/03/a-fast-16-bit-random-number-generator/

Mam pytanie, czy można mieć kod tego generatora w swoich programach? Jest
jakaś licencja?

Pierwsza uwaga: zdecydowałem się brać 16 bitów z tego generatora, jakby
brać 32 bity to powinien być dwa razy szybszy, ale nie wiem jak z 
jakością generowanych liczb:

Z takich testów na kolanie wynika, że generowanie 2^34 liczb tym
generatorem zajmuje (w moim środowisku, w mojej implementacji) 
niecałe 53 sekundy:

time ./MRndCPP 
1187849313
1737517433
2503948343
1106027281
4156358698
3197141134
216794925334129

real    0m52.735s
user    0m52.678s
sys     0m0.044s


Dla porównania standardowa implementacja generatora MT19937_64
zajmuje niecałe 101 sekund (w tych samych warunkach):

time ./MRndCPP 
655014610
3386838144
192173729
1854295942
901277944
864046005
271149186579787

real    1m40.958s
user    1m40.701s
sys     0m0.220s


Kilka testów z diehardera zaliczył:

time ./MRndCPP | dieharder -g200 -a -k2        
#=============================================================================#
#            dieharder version 3.31.1 Copyright 2003 Robert G. Brown          #
#=============================================================================#
   rng_name    |rands/second|   Seed   |
stdin_input_raw|  4.05e+07  |3620339557|
#=============================================================================#
        test_name   |ntup| tsamples |psamples|  p-value |Assessment
#=============================================================================#
   diehard_birthdays|   0|       100|     100|0.28928174|  PASSED  
      diehard_operm5|   0|   1000000|     100|0.92947482|  PASSED  
  diehard_rank_32x32|   0|     40000|     100|0.09239713|  PASSED  
    diehard_rank_6x8|   0|    100000|     100|0.10209052|  PASSED  
   diehard_bitstream|   0|   2097152|     100|0.51264249|  PASSED  
        diehard_opso|   0|   2097152|     100|0.58815248|  PASSED  
        diehard_oqso|   0|   2097152|     100|0.24822190|  PASSED  
         diehard_dna|   0|   2097152|     100|0.06963961|  PASSED  
diehard_count_1s_str|   0|    256000|     100|0.85895222|  PASSED  
diehard_count_1s_byt|   0|    256000|     100|0.99856981|   WEAK   
 diehard_parking_lot|   0|     12000|     100|0.28041223|  PASSED  
    diehard_2dsphere|   2|      8000|     100|0.97118447|  PASSED  
    diehard_3dsphere|   3|      4000|     100|0.14383896|  PASSED  
     diehard_squeeze|   0|    100000|     100|0.58457683|  PASSED  
        diehard_sums|   0|       100|     100|0.97203656|  PASSED  
        diehard_runs|   0|    100000|     100|0.20272162|  PASSED  
        diehard_runs|   0|    100000|     100|0.08707306|  PASSED  
       diehard_craps|   0|    200000|     100|0.55675752|  PASSED  
       diehard_craps|   0|    200000|     100|0.09543829|  PASSED  
^C

real    3m20.230s
user    3m27.124s
sys     0m9.833s


Druga seria:

time ./MRndCPP | dieharder -g200 -a -k2
#=============================================================================#
#            dieharder version 3.31.1 Copyright 2003 Robert G. Brown          #
#=============================================================================#
   rng_name    |rands/second|   Seed   |
stdin_input_raw|  4.22e+07  |2165006581|
#=============================================================================#
        test_name   |ntup| tsamples |psamples|  p-value |Assessment
#=============================================================================#
   diehard_birthdays|   0|       100|     100|0.55410893|  PASSED  
      diehard_operm5|   0|   1000000|     100|0.59858393|  PASSED  
  diehard_rank_32x32|   0|     40000|     100|0.64476682|  PASSED  
    diehard_rank_6x8|   0|    100000|     100|0.58918209|  PASSED  
   diehard_bitstream|   0|   2097152|     100|0.15585271|  PASSED  
        diehard_opso|   0|   2097152|     100|0.83986652|  PASSED  
        diehard_oqso|   0|   2097152|     100|0.33147055|  PASSED  
         diehard_dna|   0|   2097152|     100|0.57772809|  PASSED  
diehard_count_1s_str|   0|    256000|     100|0.35450456|  PASSED  
diehard_count_1s_byt|   0|    256000|     100|0.56128063|  PASSED  
 diehard_parking_lot|   0|     12000|     100|0.91059716|  PASSED  
    diehard_2dsphere|   2|      8000|     100|0.20089094|  PASSED  
    diehard_3dsphere|   3|      4000|     100|0.83251195|  PASSED  
     diehard_squeeze|   0|    100000|     100|0.98232982|  PASSED  
        diehard_sums|   0|       100|     100|0.03112434|  PASSED  
        diehard_runs|   0|    100000|     100|0.14326371|  PASSED  
        diehard_runs|   0|    100000|     100|0.85723327|  PASSED  
       diehard_craps|   0|    200000|     100|0.06862104|  PASSED  
       diehard_craps|   0|    200000|     100|0.91890513|  PASSED  
^C

real    4m3.343s
user    4m12.231s
sys     0m11.024s

Pobieżne testy z practrand też przechodzi:
time ./MRndCPP | ../../PractRand/RNG_test stdin
RNG_test using PractRand version 0.93
RNG = RNG_stdin, seed = 0xf0ae5889
test set = normal, folding = standard(unknown format)

rng=RNG_stdin, seed=0xf0ae5889
length= 128 megabytes (2^27 bytes), time= 2.6 seconds
  no anomalies in 151 test result(s)

rng=RNG_stdin, seed=0xf0ae5889
length= 256 megabytes (2^28 bytes), time= 6.0 seconds
  no anomalies in 162 test result(s)

rng=RNG_stdin, seed=0xf0ae5889
length= 512 megabytes (2^29 bytes), time= 11.7 seconds
  no anomalies in 171 test result(s)

rng=RNG_stdin, seed=0xf0ae5889
length= 1 gigabyte (2^30 bytes), time= 23.2 seconds
  no anomalies in 183 test result(s)

rng=RNG_stdin, seed=0xf0ae5889
length= 2 gigabytes (2^31 bytes), time= 46.2 seconds
  no anomalies in 194 test result(s)

rng=RNG_stdin, seed=0xf0ae5889
length= 4 gigabytes (2^32 bytes), time= 87.7 seconds
  no anomalies in 203 test result(s)

rng=RNG_stdin, seed=0xf0ae5889
length= 8 gigabytes (2^33 bytes), time= 171 seconds
  Test Name                         Raw       Processed     Evaluation
  BCFN(2+2,13-0,T)                  R=  -8.3  p =1-2.4e-4   unusual          
  ...and 214 test result(s) without anomalies

rng=RNG_stdin, seed=0xf0ae5889
length= 16 gigabytes (2^34 bytes), time= 340 seconds
  no anomalies in 226 test result(s)

^C

real    5m46.927s
user    5m43.989s
sys     0m12.371s


Na lepsze testy trzeba poczekać, chyba że z powodu licencji będę musiał 
wyrzucić to ze swojego zestawu generatorów.

Pozdrawiam
Technical Details
Message-ID: <82f8e967-0d0e-4bae-b005-aacb301b2349@googlegroups.com>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed.pionier.net.pl!3.eu.feeder.erje.net!feeder.erje.net!weretis.net!feeder7.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!g89no437322qtd.0!news-out.google.com!o19ni2119qtr.1!nntp.google.com!g89no437315qtd.0!postnews.google.com!google-groups.googlegroups.com!not-for-mail
References: <ed3041b7-c05f-43f3-887a-9a12a9633741@googlegroups.com> <2104ea83-5daa-4752-9a63-ed3346a14082@googlegroups.com>

Show Full Headers
Complete Article Headers
X-Received: by 2002:ac8:47cc:: with SMTP id d12mr37825700qtr.246.1577432699959;        Thu, 26 Dec 2019 23:44:59 -0800 (PST)
X-Received: by 2002:a81:13cd:: with SMTP id 196mr37735883ywt.43.1577432699731; Thu, 26 Dec 2019 23:44:59 -0800 (PST)
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed.pionier.net.pl!3.eu.feeder.erje.net!feeder.erje.net!weretis.net!feeder7.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!g89no437322qtd.0!news-out.google.com!o19ni2119qtr.1!nntp.google.com!g89no437315qtd.0!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: pl.comp.lang.c
Date: Thu, 26 Dec 2019 23:44:59 -0800 (PST)
In-Reply-To: <2104ea83-5daa-4752-9a63-ed3346a14082@googlegroups.com>
Complaints-To: groups-abuse@google.com
Injection-Info: google-groups.googlegroups.com; posting-host=77.254.46.242; posting-account=xjvq9QoAAAATMPC2X3btlHd_LkaJo_rj
NNTP-Posting-Host: 77.254.46.242
References: <ed3041b7-c05f-43f3-887a-9a12a9633741@googlegroups.com> <2104ea83-5daa-4752-9a63-ed3346a14082@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <82f8e967-0d0e-4bae-b005-aacb301b2349@googlegroups.com>
Subject: Re: Optymalizacja kodu
From: "M.M." <mmarszik@gmail.com>
Injection-Date: Fri, 27 Dec 2019 07:44:59 +0000
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit