LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

slow string

Solved!
Go to solution

Hello.

 

I want to take a file and remove every line that starts with an '!' and save the file to a single string.

 

After some hours of work and a lot of googling around, I finally implemented something that works, but it is way too slow, it needs about 2 seconds for a 1140 lines file.

 

It is obvious that the way I am handling the string is awful, but I cannot find another way to do it.

 

Can anyone help me with tips and tricks to make it work a lot faster?

 

I am using LabVIEW 2014, because it is new, I am also attaching a saved version of 2011.

 

Thanks everyone.

Download All
0 Kudos
Message 1 of 14
(3,624 Views)

I dealt with a similar issue a few weeks ago. The reason your code is running slowly is likely becasue it is building the string as it goes. This means that every time you build the string, you request a new chunk of memory which is slow. LV sometimes recognises this and optimises things for you, but it might not be doing that now.

 

A faster way would be to make a large empty array at the begining, replace values instead of adding them, then remove the remaining empty values at the end. Hope that helps!

0 Kudos
Message 2 of 14
(3,617 Views)
Solution
Accepted by topic author vakost

First, I would read the entire file in one shot.  You are using a lot of time constantly opening and closing that file.  That is likely a very large percentage of your time.  From there, use a FOR loop and do your check.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 3 of 14
(3,613 Views)

Capture.PNG

 

That conditional thing there is pretty neat. Is that new in 2013?

 

Also, what is that second block? I don't recognize it.

0 Kudos
Message 4 of 14
(3,606 Views)

@awood04 wrote:

Capture.PNG

 

That conditional thing there is pretty neat. Is that new in 2013?

 

Also, what is that second block? I don't recognize it.


The conditional terminal was new with 2012.

 

That second block is actually the Concatenate String reduced to just 1 element.  When you use the Concatenate String on an array of strings, it just concatenates all of the elements of the array into a single string.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 5 of 14
(3,601 Views)

Amazing!

 

It is way too fast now and the cool thing is that it saved me some time from another formatting I wanted to do.

 

I am also a bit confused now. When am I going to learn how to write that efficient code myself?

 

Thanks again.

0 Kudos
Message 6 of 14
(3,594 Views)

 

Cool trick with the concatenate strings block!

 

I usually end op writing unbearably slow code, then thinking of a better way the next day either while showering or drinking my morning coffee.  Smiley Happy

0 Kudos
Message 7 of 14
(3,584 Views)

vakost wrote:

I am also a bit confused now. When am I going to learn how to write that efficient code myself?


What are you confused about?  Anything we can shed some light on?

 

Efficient code comes with experience.  I've been learning these tricks for almost 10 years now...and still learning.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 8 of 14
(3,574 Views)

Forgive me, English is not my mother tongue.

 

What I mean is not confused but rather frustrated because I could not even come close to the solution you posted.

 

Again, I am only writing code for some months now.

 

Cheers!

0 Kudos
Message 9 of 14
(3,570 Views)

vakost wrote:

Again, I am only writing code for some months now.


Like I said, it takes time.  I was much worse off than you when I was using LabVIEW for just a few months.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 10 of 14
(3,565 Views)