Cryptonatica numbers in .NET faster System.Random()?

Please explain why (at least in tests PascalABC.NET) code no 1 works faster ~ 3 times than the code No. 2?
//No. 1
var
 arr: array of byte;
 rndg := new System.Security.Cryptography.RNGCryptoServiceProvider();

begin
 setlength(arr, 10000000);
rndg.GetBytes(arr);
 write(milliseconds());//from 50 to 70
end.

//No. 2
var
 arr: array of byte;
 rnd := System new.Random();

begin
 setlength(arr, 10000000);
rnd.NextBytes(arr);
 write(milliseconds);//from 160 to 200
end.


Why generation cryptonatica (for documentation .NET) random requires significantly less time than the standard?

(with increasing length of the array to 100 million items on cryptocercidae spent ~ 0.3, and the standard is somewhere 1.5)
(by the way: @ test 1 billion kriptologii noticeable weighty loss of memory, even though all were calculated over 41; in a similar test of 1 billion standard-random spent 18 seconds (SUDDENLY), and freezes spending memory was not particularly (memory not measured, just a General sense from the "behavior" of the computer)).

Total, change the question just asked to comment on this behavior .NET'a (.NET and???), possible explaining it; including an interesting "kink" 1 billion bytes.
June 3rd 19 at 20:19
2 answers
June 3rd 19 at 20:21
Solution
I guess, but it's not exactly in the first case, you are returning some data that was already generated by the system and you have access to them. In the second you generate them on the fly.

The turning point in my view is obvious, at some point it becomes too difficult to generate everything on the fly. While the second case continues to generate a certain speed.

And maybe just not enough RAM and leave the data in the paging file with all its shortcomings.
June 3rd 19 at 20:23
Solution
I believe that the generation is called from the external crypto-optimized unsafe code. while normal, there are likely a lot of overhead work (GC, bounds checking of arrays). well, measure learn, I have such data after the test

BenchmarkDotNet=v0.10.14, OS=Windows 10.0.16299.547 (1709/FallCreatorsUpdate/Redstone3)
Intel Core i7-4770K CPU 3.50 GHz (Haswell), 1 CPU, 8 logical and 4 physical cores
Frequency=3423912 Hz, Resolution=292.0636 ns, Timer=TSC
[Host] : .NET Framework 4.6.2 (CLR 4.0.30319.42000), LegacyJIT 32bit-v4.7.3130.0
DefaultJob : .NET Framework 4.6.2 (CLR 4.0.30319.42000), LegacyJIT 32bit-v4.7.3130.0

Method | I | Mean | Error | StdDev | Rank |
------- |---------- |---------------:|--------------:|--------------:|-----:|
Cripto | 10000 | us of 5,620 | 0.0032 us | us 0.0029 | 1 |
Simple | 10000 | 84.398 us | 0.0452 us | us 0.0401 | 2 |
Cripto | 100000000 | 94,948.080 us | 1,126.6868 us | 1,053.9034 us | 3 |
Simple | 100000000 | 854,149.505 us | 2,348.7335 us | 2,197.0066 us | 4 |

// * Hints *
Outliers
CryptoVsSimpleRandom.Simple: Default -> 1 outlier was removed

// * Legends *
I : Value of the 'I' parameter
Mean : Arithmetic mean of all measurements
Error : Half of a 99.9% confidence interval
StdDev : Standard deviation of all measurements
Rank : Relative position of current benchmark mean among all benchmarks (Arabic style)
1 us : 1 Microsecond (0.000001 sec)

used BenchmarkDotNet

Find more questions by tags .NET