1function test113
2%TEST113 performance tests for GrB_kron
3
4% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
5% SPDX-License-Identifier: Apache-2.0
6
7fprintf ('test113: performance tests for GrB_kron\n') ;
8
9[save save_chunk] = nthreads_get ;
10chunk = 4096 ;
11ncores = feature ('numcores') ;
12
13A = sprand (310, 302, 0.1) ;
14B = sprand (300, 301, 0.1) ;
15fprintf ('nnz(A) %g\n', nnz (A)) ;
16fprintf ('nnz(B) %g\n', nnz (B)) ;
17fprintf ('nnz(C) %g\n', nnz (A) * nnz (B)) ;
18
19tic
20C = kron (A,B) ;
21tm = toc ;
22fprintf ('MATLAB: %g sec\n', tm) ;
23
24[m n] = size (C) ;
25Empty = sparse (m,n) ;
26
27for nthreads = [1 2 4 8 16 20 40]
28
29    if (nthreads > 2*ncores)
30        break ;
31    end
32
33    nthreads_set (nthreads,chunk) ;
34
35    tic
36    C1 = GB_mex_kron (Empty, [ ], [ ], 'times', A, B) ;
37    t (nthreads) = toc ;
38
39    assert (isequal (C, C1.matrix)) ;
40
41    fprintf ('GB: %12.4f sec speedup: %12.4f  vs MATLAB: %12.4f\n', ...
42        t (nthreads), t (1) / t (nthreads), tm / t (nthreads)) ;
43
44end
45
46nthreads_set (save, save_chunk) ;
47