Back to the main page.

Bug 1773 - ft_read_header should be made faster

Status CLOSED FIXED
Reported 2012-10-09 20:55:00 +0200
Modified 2012-10-29 13:44:58 +0100
Product: FieldTrip
Component: realtime
Version: unspecified
Hardware: PC
Operating System: Mac OS
Importance: P3 normal
Assigned to: Robert Oostenveld
URL:
Tags:
Depends on:
Blocks: 738
See also:

Robert Oostenveld - 2012-10-09 20:55:56 +0200

I am simulating a localhost data stream with sine2ft and a stand-alone buffer. It writes 16 channels at 2000Hz with a blocksize of 512 samples (so ~4x PUT_DAT per second). Then to get a reference measurement I do the following in MATLAB >> tic; for i=1:1000, ft_read_header('buffer://localhost:1972'); end; toc Elapsed time is 8.863868 seconds. So it takes ~8 ms per read operation.


Robert Oostenveld - 2012-10-09 21:02:04 +0200

with "profile on, running the code, profile report", I see that line 101 in ft_read_header takes a considerable amount of time When I change that from if ~exist(filename, 'file') && ~strcmp(ft_filetype(filename), 'fcdc_buffer') && ~strcmp(ft_filetype(filename), 'ctf_shm') && ~strcmp(ft_filetype(filename), 'fcdc_mysql') into if ~strcmp(ft_filetype(filename), 'fcdc_buffer') && ~strcmp(ft_filetype(filename), 'ctf_shm') && ~strcmp(ft_filetype(filename), 'fcdc_mysql') && ~exist(filename, 'file') So I moved the exist call to the end and the check on fcdc_buffer to the begin (using the short-circuited "&&" in the test). Then I try again and get >> tic; for i=1:1000, ft_read_header('buffer://localhost:1972'); end; toc Elapsed time is 1.783376 seconds. so ~2ms per call. I presume this is fast enough for BCI applications. The profiler is really easy to use, so please give it a try next time.


Robert Oostenveld - 2012-10-09 21:02:52 +0200

mbp> svn commit ft_read_header.m Sending ft_read_header.m Transmitting file data . Committed revision 6712.


Robert Oostenveld - 2012-10-09 21:06:41 +0200

I have made the same change to ft_read_data mbp> svn commit ft_read_data.m Sending ft_read_data.m Transmitting file data . Committed revision 6713.


Robert Oostenveld - 2012-10-29 13:44:58 +0100

changed the status of several bugs that were RESOLVED some time ago to CLOSED