-
Notifications
You must be signed in to change notification settings - Fork 0
/
BenchmarkTester.m
57 lines (54 loc) · 2.07 KB
/
BenchmarkTester.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
classdef BenchmarkTester
properties
iterations
calculators
cpuCalculator
gpuCalculator
gpuFunArrayCalculator
cudaCalculator
end
methods
function obj = BenchmarkTester(handles)
obj.iterations = [10, 100];
obj.cpuCalculator = CPUCalculator(handles);
obj.gpuCalculator = GPUCalculator(handles);
obj.gpuFunArrayCalculator = GPUArrayFunCalculator(handles);
obj.cudaCalculator = CUDACalculator(handles);
disp('init');
end
function [benchmarkArray, count] = runBenchmark(obj)
benchmarkArray = [];
for iteration=obj.iterations
benchmarkArray = [benchmarkArray, runForIteration(obj, iteration)];
end
count = 0;
end
function calcTimes = runForIteration(obj, iteration)
fprintf( 'running with gridsize %d x %d and %1.0f iterations: ', length(obj.cpuCalculator.xGrid), length(obj.cpuCalculator.yGrid), iteration);
calcTimes = [];
calcTimes = [calcTimes; runTest(obj, obj.cpuCalculator, iteration)];
fprintf( '...CPU ');
calcTimes = [calcTimes; runTest(obj, obj.gpuCalculator, iteration)];
fprintf( '...GPU ');
calcTimes = [calcTimes; runTest(obj, obj.gpuFunArrayCalculator, iteration)];
fprintf( '...FunArray ');
calcTimes = [calcTimes; runTest(obj, obj.cudaCalculator, iteration)];
fprintf( '...CUDA\n');
end
function calcTime = runTest(obj, calculator, iteration)
M = 2;
N = 1;
% make sure compiler made improvements and caching
%for i = 1:M
% calc(calculator, iteration);
%end
% calc 5 times and take avg
for i = 1:N
t = tic();
calc(calculator, iteration);
calcTime = toc(t);
end
calcTime = calcTime / N;
end
end
end