help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: slow code, optimisation advice needed


From: PhilipNienhuis
Subject: Re: slow code, optimisation advice needed
Date: Wed, 30 May 2018 11:29:09 -0700 (MST)

tomkut wrote
> Dear Octavers
> 
> Would anyone be so kind and offer advice on speeding up the below (the
> loop
> takes a long time)?
> a = fileread ("C:/Backup/Thermo Backups/2018-05-17.txt"); 
> d = strsplit (a, "\n");
> for i = 1 : length(d) 
>  e (i , :) = strsplit ( d{i} );
> endfor 

Others have focused on the file I/O, but the rest can be speeded up as well.
It is useful to do as follows:

profile clear;
profile on;
:
<your code>
:
profile off;
profshow

to find out where most of the time is spent.

OK, as regards your code:
for loops are usually killing for performance.
I haven't tried myself but instead of the for loop you can try vectorizing
with cellfun along the lines of;

e = cellfun (@strsplit, d)

(maybe "uni, 0" are required as 3rd and 4th arg to cellfun)

(It seems that cellfun() works the fastest when given handles to functions.)

Philip 



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html



reply via email to

[Prev in Thread] Current Thread [Next in Thread]