LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sorting lines in array depending of first character - speed-problem

Solved!
Go to solution

Hello,

i have a text-file with lots of lines. The file is imported to LV and need to be sorted by first character.

It works fine but gets very slow if too much lines.

If 40.000 lines then it takes 0.2s.

If 400.000 lines then the time rises with factor 100 to 25s.

if 1.000.000 lines then the time is 222sec (~4min)

 

Attached the code that sorts a text-array.

The number of lines can be set with the loop-counter (Loop-counter *4 = NumberOfLines)

The elapsed time is displayed.

 

How can i speed this up? (Or make the elapsed time more linear to the number of lines)

 

Thanks

Clipboard01.jpg

0 Kudos
Message 1 of 11
(3,671 Views)
Solution
Accepted by topic author OnlyOne

You can try something like this. If you process an array line by line you always end up taking long time.

SortArray.png

 

 Sorry I have some problem attaching the VI.

-----

The best solution is the one you find it by yourself
Message 2 of 11
(3,658 Views)

Looks good, but what is this icon in the small for-loop?

Thx

0 Kudos
Message 3 of 11
(3,643 Views)

Its the same "String subset" primitive.

-----

The best solution is the one you find it by yourself
Message 4 of 11
(3,637 Views)

Speed is great now.

 

Only one problem with the "Sorting".

The lines contain a timestemp and now i have the wrong order after sorting.

How can i change it that the order is the same as in input-array and it only sorts by "first character"?

 

Thx

0 Kudos
Message 5 of 11
(3,618 Views)

Can you show the code that you modified and also attach the text file if possible to see the type of data.

-----

The best solution is the one you find it by yourself
Message 6 of 11
(3,604 Views)

It is exactly your code that i am executing only different input data.

 

For example:

C|5|20140911-165529|7|S1|5,000|0,001|1

C|5|20140911-165629|7|S1|5,000|0,001|1

C|1|20140911-165729|7|S1|5,000|0,001|1

C|1|20140911-165829|7|S1|5,000|0,001|1

C|5|20140911-165929|7|S1|5,000|0,001|1

 

Here the timestamp is going higher each line, but because the third-character changes from "5" to "1" the Sorting will put these lines to the beginning.

And this changes the order of the tiimestamp after sorting.

0 Kudos
Message 7 of 11
(3,601 Views)

Try sorting this way. This worul take little more time than the previous one for sorting.

 

SortArrayMod.png

-----

The best solution is the one you find it by yourself
Message 8 of 11
(3,587 Views)
Solution
Accepted by topic author OnlyOne

SortSnippet.png

Like this?

Message 9 of 11
(3,584 Views)

Nice solution.

 

For this you must know the 1st character, in my solution its not required. I like the solution though

-----

The best solution is the one you find it by yourself
Message 10 of 11
(3,574 Views)