# turn off pager; do not want the tests to be waiting for input...
more off

# where benchmarks files are stored
dir_benchmarks = "~/share/prog/octave/benchmarks/octave-benchmark2/inst";
# where bench_utils are (working with the uninstalled version)
addpath(dir_benchmarks)

# for cprintf
addpath("~/share/prog/octave/cprintf")

dir_sets = "sets/18505";
mkdir(dir_sets)

# set action="run" and execute this script once in each version of octave
# (not simultaneously, of course)
# the set action="compare" and execute this script for side-by-side comparison

# action = "run";
action = "compare";
switch action
case "run"
	# tested: boot with isolcpus=3,4,5
	# used the last two isolated cores for octave:
	cpu_str = "4-5"
	[status, output] = system(sprintf("taskset -a -c -p %s %d",  cpu_str, getpid()));
	assert(status, 0, output)
	
	results = struct();
	group_names = {"dtmm", "stmm", "index", "intmath", "permute"};
	# group_names = {"index", "permute"};
	N_b = numel(group_names);
	N_repeat = 2;
	for idx_r = 1:N_repeat
		for idx = 1:N_b
			name = group_names{idx};
			fun = str2func(sprintf("benchmark_%s", name));
			group_results = fun();
			if idx == 1
				results = group_results;
			else
				# could also use vertcat to get a 2D struct array
				results = horzcat(results, group_results);
			endif
		endfor
		filename = sprintf("benchmarks_v%s_%d.hdf5", version(), idx_r);
		save("-hdf5", fullfile(dir_sets, filename), "results")
	endfor
	
	
case "compare"
	versions = {"4.2.1", "4.4.0"};
	results_c = {};
	for idx = 1:numel(versions)
		N_repeat = 2;
		for idx_r = 1:N_repeat
			filename = sprintf("benchmarks_v%s_%d.hdf5", versions{idx}, idx_r);
			load(fullfile(dir_sets, filename), "results")
			results_c{end+1} = results;
		endfor
	endfor
	bench_compare(results_c{:});
endswitch
