Quantcast
Viewing all articles
Browse latest Browse all 15

Matlab Performance using Java

Hi,

I just start to use Java inside Matlab in order to read from the ethernet. The program right now is quite simple, it only read 53 doubles @ 1000Hz more or less.
The problem is that I am not getting all the data, some of the packages are lost because I don't read them fast enough (I am working using local host, so they cannot be lost in other step).
The processor is a i7-2600@3.4GHz so it shouldn't be a problem, in the past I did something similar with C and I didn't had any problem. Is it possible that because the language is interpreted I cannot reach that speed reading data?

Just in case I put the code if there is something I'm doing wrong.

    import java.net.ServerSocket
    import java.io.*
    j=1;
    i=0;
    server_socket = [];
    input_socket = [];
    while (1)
        try
            i= i+1;
            fprintf(1, 'Trying to connect %d\n',i);
            server_socket = ServerSocket(31415);
            server_socket.setSoTimeout(5000);
            input_socket = server_socket.accept;
            fprintf(1, 'Client connected\n');
            while (1)
                %Reading part
                input_stream = input_socket.getInputStream;
                d_input_stream = DataInputStream(input_stream);
                bytes_available = input_stream.available;
                if(bytes_available>0)
                    for i =1:53
                        result(i,j)= d_input_stream.readDouble();
                    end
                    j=j+1;
                end
            end
            
            % cleanup
            input_socket.close;
        catch
            if ~isempty(server_socket)
                server_socket.close;
            end
            
            if ~isempty(input_socket)
                input_socket.close
            end

            % pause before retrying
            %pause(1);
        end
   end


The only point that I see can be improved is reserving memory for the variable result, but when I start I don't know the size of the variable.

Viewing all articles
Browse latest Browse all 15

Trending Articles