%   Benchmark based on an integer factorization problem.
%
%   Copyright 2018-2020 The MathWorks, Inc.

complexities = [2^18 2^20 2^21 2^22];
numWorkers = [1 2 4 6 16 32 64];

time = zeros(numel(numWorkers),numel(complexities));

% To obtain predictable sequences of composite numbers, fix the seed
% of the random number generator.
rng(0,'twister');

for c = 1:numel(complexities)
    
    primeNumbers = primes(complexities(c));
    compositeNumbers = primeNumbers.*primeNumbers.*primeNumbers(randperm(numel(primeNumbers)));
    factors = zeros(numel(primeNumbers),2);
    
    for w = 1:numel(numWorkers)
        tic;
        parfor (idx = 1:numel(compositeNumbers), numWorkers(w))
            factors(idx,:) = factor(compositeNumbers(idx));
        end
        time(w,c) = toc;
    end
end