1function test68(n)
2%TEST68 performance tests for eWiseMult
3
4% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
5% SPDX-License-Identifier: Apache-2.0
6
7fprintf ('\ntest68 --------------------------- quick test of GrB_eWiseMult\n') ;
8
9[save save_chunk] = nthreads_get ;
10chunk = 4096 ;
11nthreads = feature ('numcores') ;
12nthreads_set (nthreads, chunk) ;
13
14rng ('default') ;
15
16if (nargin < 1)
17    n = 3000 ;
18end
19
20A = sparse (rand (n)) ;
21B = sparse (rand (n)) ;
22C = sparse (n,n) ;
23
24for trial = 1:2
25    % C = A.*B, no mask
26    Afull = full (A) ;
27    Bfull = full (B) ;
28
29    tic
30    C0 = Afull .* Bfull ;
31    tf = toc ;
32    fprintf ('MATLAB, full: %0.4f\n', tf) ;
33
34    tic
35    C0 = A .* B ;
36    t0 = toc ;
37
38    tic
39    C1 = GB_mex_Matrix_eWiseMult  (C, [ ], [ ], 'times', A, B, [ ]);
40    t1 = toc ;
41    fprintf ('MATLAB %0.4f  GB %0.4f speedup %g\n', t0, t1, t0/t1) ;
42    assert (isequal (C0, C1.matrix)) ;
43end
44
45A = sprand (n, n, 0.001) ;
46
47    % C = A.*B, no mask
48    tic
49    C0 = A .* B ;
50    t0 = toc ;
51    tic
52    C1 = GB_mex_Matrix_eWiseMult  (C, [ ], [ ], 'times', A, B, [ ]);
53    t1 = toc ;
54    fprintf ('MATLAB %0.4f  GB %0.4f speedup %g\n', t0, t1, t0/t1) ;
55    assert (isequal (C0, C1.matrix)) ;
56
57A = sparse (n, n) ;
58A (n,:) = 1 ;
59
60    % C = A.*B, no mask
61    tic
62    C0 = A .* B ;
63    t0 = toc ;
64    tic
65    C1 = GB_mex_Matrix_eWiseMult  (C, [ ], [ ], 'times', A, B, [ ]);
66    t1 = toc ;
67    fprintf ('MATLAB %0.4f  GB %0.4f speedup %g\n', t0, t1, t0/t1) ;
68    assert (isequal (C0, C1.matrix)) ;
69
70A = sparse (n, n) ;
71A (1,:) = 1 ;
72
73    % C = A.*B, no mask
74    tic
75    C0 = A .* B ;
76    t0 = toc ;
77    tic
78    C1 = GB_mex_Matrix_eWiseMult  (C, [ ], [ ], 'times', A, B, [ ]);
79    t1 = toc ;
80    fprintf ('MATLAB %0.4f  GB %0.4f speedup %g\n', t0, t1, t0/t1) ;
81    assert (isequal (C0, C1.matrix)) ;
82
83for d =  [0.000:0.002:0.1]
84    A = sprand (n, n, d) ;
85
86    % C = A.*B, no mask
87    tic
88    C0 = A .* B ;
89    t0 = toc ;
90    tic
91    C1 = GB_mex_Matrix_eWiseMult  (C, [ ], [ ], 'times', A, B, [ ]);
92    t1 = toc ;
93    fprintf ('d %8.3f MATLAB %0.4f  GB %0.4f speedup %g\n', d, t0, t1, t0/t1) ;
94    assert (isequal (C0, C1.matrix)) ;
95end
96
97nthreads_set (save, save_chunk) ;
98