clear; % Data format long; % Load data from file y1 = load('results_benchmark_posix.txt'); y2 = load('results_benchmark_go.txt'); % Size of data block sizeBlock = size(y1,1)/size(y1,2); % Array for precision precisionPi1 = abs(pi-y1(:,4)); precisionPi2 = abs(pi-y2(:,4)); % Compute relevant ratio for i = 1:size(y1,2) % Precision precisionPi1(1+(i-1)*sizeBlock:i*sizeBlock); precisionPi2(1+(i-1)*sizeBlock:i*sizeBlock); % Ratio of performances = log((delta_precision*runtime)^-1) ratio1(1+(i-1)*sizeBlock:i*sizeBlock) = log((y1(1+(i-1)*sizeBlock:i*sizeBlock,3).*(precisionPi1(1+(i-1)*sizeBlock:i*sizeBlock))).^(-1)); ratio2(1+(i-1)*sizeBlock:i*sizeBlock) = log((y2(1+(i-1)*sizeBlock:i*sizeBlock,3).*(precisionPi2(1+(i-1)*sizeBlock:i*sizeBlock))).^(-1)); end % Declare gaps and arrays spaceGap = 2; gap2 = sizeBlock; gap1 = gap2 + spaceGap; x1_final = zeros(size(y1,2),sizeBlock+gap1); y1_final = zeros(size(y1,2),sizeBlock+gap1); x2_final = zeros(size(y2,2),sizeBlock+gap2); y2_final = zeros(size(y2,2),sizeBlock+gap2); %Block to repeat for i = 1:size(y1,2) x1_final(i,:) = [(1+(i-1)*sizeBlock+(i-1)*gap1:i*sizeBlock+(i-1)*gap1) zeros(gap1,1)']; y1_final(i,:) = [ratio1(1+(i-1)*sizeBlock:i*sizeBlock) zeros(gap1,1)']; x2_final(i,:) = [zeros(gap2,1)' (1+(i-1)*sizeBlock+(i*gap2)+(i-1)*(gap1-gap2):i*sizeBlock+i*gap2+(i-1)*(gap1-gap2))]; y2_final(i,:) = [zeros(gap2,1)' ratio2(1+(i-1)*sizeBlock:i*sizeBlock)]; end % Build x_full and y_full x1_full = x1_final(1,:); y1_full = y1_final(1,:); x2_full = x2_final(1,:); y2_full = y2_final(1,:); % Concatenate vectors for i = 1:(size(y1,2)-1) x1_full = horzcat(x1_full,x1_final(i+1,:)); y1_full = horzcat(y1_full,y1_final(i+1,:)); x2_full = horzcat(x2_full,x2_final(i+1,:)); y2_full = horzcat(y2_full,y2_final(i+1,:)); end % Plot histograms figure('Color','w'); title('Bar with height-dependant color'); % Convert y1_full vector to colors y1_color = vals2colormap(y1_full,'cool'); for k = 1:numel(x1_full) if (x1_full(k) ~= 0) bar_h1 = bar(x1_full(k),y1_full(k),'BarWidth',1); set(bar_h1,'FaceColor',y1_color(k,:)); hold on; end end % Convert y1_full vector to colors y2_color = 1-0.8*vals2colormap(y2_full,'gray'); for k = 1:numel(x2_full) if (x2_full(k) ~= 0) bar_h2 = bar(x2_full(k),y2_full(k),'BarWidth',1); set(bar_h2,'FaceColor',y2_color(k,:)); hold on; end end % Xlim xlim([0 max(x2_full)+1]); % Xtick and Xtickslabel set(gca, 'XTick',(1:2:7)*sizeBlock+(0:3)*spaceGap,'XTickLabel',{'1 MB', '16 MB', '256 MB', '4 GB'}); % Xlabel and Ylabel xlabel('size of loop'); ylabel('log((\epsilon\Deltat)^-1)'); % Legends l=legend([bar_h1 bar_h2], 'PosixThreads', 'GoRoutines'); rect=[0.75, 0.8, 0.1, 0.1]; set(l,'Position',rect,'color','none'); % plot average with rectangles heightRect = 0.5; for i = 1:size(y1,2) average_posix(i) = sum(ratio1(1+(i-1)*sizeBlock:i*sizeBlock))/sizeBlock; average_go(i) = sum(ratio2(1+(i-1)*sizeBlock:i*sizeBlock))/sizeBlock; h1 = rectangle('Position', [(0.5+(i-1)*(2*sizeBlock+(gap1-gap2))) average_posix(i) sizeBlock-0.5 heightRect], 'FaceColor', 'm', 'EdgeColor', 'c', 'LineWidth', 2); h2 = rectangle('Position', [(0.5+(i-1)*(2*sizeBlock+(gap1-gap2))+sizeBlock) average_go(i) sizeBlock-0.5 heightRect], 'FaceColor', 'k', 'EdgeColor', [0.5 0.5 0.5], 'LineWidth', 2); end function rgb = vals2colormap(vals, colormap, crange) % Take in a vector of N values and return and return a Nx3 matrix of RGB % values associated with a given colormap % % rgb = AFQ_vals2colormap(vals, [colormap = 'jet'], [crange]) % % Inputs: % vals = A vector of values to map to a colormap or a cell array of % vectors of values % colormap = A matlab colormap. Examples: colormap = 'autumn'; % colormap = 'jet'; colormap = 'hot'; % crange = The values to map to the minimum and maximum of the colormap. % Defualts to the full range of values in vals. % % Outputs: % rgb = Nx3 matrix of rgb values mapping each value in vals to the % corresponding rgb colors. If vals is a cell array then rgb % will be a cell array of the same length % % Example: % vals = rand(1,100); % rgb = AFQ_vals2colormap(vals, 'hot'); % % Copyright Jason D. Yeatman, June 2012 if ~exist('colormap','var') || isempty(colormap) colormap = 'jet'; end % if ~iscell(vals) if ~exist('crange','var') || isempty(crange) crange = [min(vals) max(vals)]; end % Generate the colormap cmap = eval([colormap '(256)']); % Normalize the values to be between 1 and 256 vals(vals < crange(1)) = crange(1); vals(vals > crange(2)) = crange(2); valsN = round(((vals - crange(1)) ./ diff(crange)) .* 255)+1; % Convert any nans to ones valsN(isnan(valsN)) = 1; % Convert the normalized values to the RGB values of the colormap rgb = cmap(valsN, :); elseif iscell(vals) if ~exist('crange','var') || isempty(crange) crange = [min(vertcat(vals{:})) max(vertcat(vals{:}))]; end % Generate the colormap cmap = eval([colormap '(256)']); for ii = 1:length(vals) % Normalize the values to be between 1 and 256 for cell ii valsN = vals{ii}; valsN(valsN < crange(1)) = crange(1); valsN(valsN > crange(2)) = crange(2); valsN = round(((valsN - crange(1)) ./ diff(crange)) .* 255)+1; % Convert any nans to ones valsN(isnan(valsN)) = 1; % Convert the normalized values to the RGB values of the colormap rgb{ii} = cmap(valsN, :); end end end