Datetime benchmark
The snippet can be accessed without any authentication.
Authored by
Rasmus Ringdahl
benchmark.m 3.54 KiB
%%
% PARAMETERS
NUM_OF_TESTS = 10;
SIZE_OF_TESTS = 2; % * 1440 + 1
%%
% Importing the right libraries.
import core.*
try
time = core.Time;
catch
setEnvironment
import core.*
end
% Setting up for the database connection.
core.Monitor.set_db_env('tal')
core.Monitor.set_prog_name('mms_matlab')
db = core.DatabaseReader();
try
% Creating statments
psDatetime = 'datetime';
query = sprintf('SELECT generate_series(now()::timestamp without time zone,now():: timestamp without time zone +Interval ''%d day'',interval ''1 minute'') AS datetime;',SIZE_OF_TESTS);
db.psCreate(psDatetime,query);
psDatenum = 'datenum';
query = sprintf('SELECT EXTRACT(EPOCH from (timeseries::timestamp without time zone - timestamp ''0001-01-01 00:00:00 AD'' + interval ''1 day''))/(3600.0*24.0)+366 AS datenum FROM (SELECT generate_series(now()::timestamp without time zone,now():: timestamp without time zone +Interval ''%d day'',interval ''1 minute'') AS timeseries) AS timeseries;',SIZE_OF_TESTS);
db.psCreate(psDatenum,query);
% Creating benchmark holders
bench_datetime = NaT(1, NUM_OF_TESTS) - NaT(1);
bench_datenum = NaT(1, NUM_OF_TESTS) - NaT(1);
for i = 1:NUM_OF_TESTS
fprintf('Starting test %d.\n',i);
init = false;
% Preforms a query.
db.psQuery(psDatetime);
fprintf('Running datetime.\n');
% Starting the time tracking.
start_time=datetime();
% Looping through the data.
while(db.psRSNext(psDatetime))
% Extracts the datetime column as a character and feeds in
% into the datetime function.
if not(init)
times = datetime(db.psRSGetVarChar(psDatetime,'datetime').toCharArray');
init = true;
else
times(end+1,1) = datetime(db.psRSGetVarChar(psDatetime,'datetime').toCharArray');
end
end
% Stops the time tracking and storing the duration.
end_time=datetime();
bench_datetime(1,i) = end_time - start_time;
fprintf('Completed datetime for %s (%d)\n',start_time, size(times,1));
init = false;
% Preforms a query.
db.psQuery(psDatenum);
fprintf('Running datenum.\n');
% Starting the time tracking.
start_time=datetime();
% Looping through the data.
while(db.psRSNext(psDatenum))
% Extracts the datenum column as a double and feeds in
% into the datetime function with the convert flag.
if not(init)
times = datetime(db.psRSGetDouble(psDatenum,'datenum').doubleValue,'convertFrom','datenum');
init = true;
else
times(end+1,1) = datetime(db.psRSGetDouble(psDatenum,'datenum').doubleValue,'convertFrom','datenum');
end
end
% Stops the time tracking and storing the duration.
end_time=datetime();
bench_datenum(1,i) = end_time - start_time;
fprintf('Completed datenum for %s (%d)\n',start_time, size(times,1));
end
catch
% Closes the connection to the database if somethings goes wrong.
db.close();
end
% Closes the connection when we are done.
db.close();
fprintf('\n*** Statistics ***\n')
fprintf('Fetch size: %d\n',size(times,1));
fprintf('Fetch time: \n');
fprintf('datetime method: %f seconds\n',seconds(mean(bench_datetime)));
fprintf('datenum method: %f seconds\n',seconds(mean(bench_datenum)));
fprintf('\n*** Test done ***\n')
Please register or sign in to comment