LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Read from text file in a loop

I have a program that extracts information from multiple log files in a folder (Folder-Value change event). This sub-program is slow taking more than 10 seconds at its bottleneck ""read from text file" function, and afterwards, it seems Labview finds an optimized technique and it subsequently takes under a second. I can't tell why the "read from text file" is slow at first and this seems to be the problem independent of the larger code, it reads quite slowly (20ms/file; 700files = 14 secs) the first time in the attached code (for different folders) and optimizes afterwards if still in memory. To see it run slowly again may require restarting your PC and running the program.

I can't figure out why and how to prevent the slow performance. I have programmed it in multiple ways - the options are in the Diagram disable structure, it still behaves that way.

 

0 Kudos
Message 1 of 7
(2,850 Views)

Your timing loop is coded incorrectly. That would explain the variable time reported.

Put the file-string through the first flat-sequence structure. That will make your timing more reliable.

---------------------------------------------
Certified LabVIEW Developer (CLD)
There are two ways to tell somebody thanks: Kudos and Marked Solutions
0 Kudos
Message 2 of 7
(2,840 Views)

I am observing the time it takes for each file to go through the loop, it takes between 10-30ms per file the first time and 0 afterwards.

Either ways, its just generally much slower to read text from file in the loop

0 Kudos
Message 3 of 7
(2,823 Views)

I have ran your code and a cleaned up version and all files take the same 0 to 1 ms time. I am using LV2016, but I doubt that would make a difference.

Have you looked at the first file in Notepad++. It might be corrupted.

---------------------------------------------
Certified LabVIEW Developer (CLD)
There are two ways to tell somebody thanks: Kudos and Marked Solutions
0 Kudos
Message 4 of 7
(2,776 Views)

Thanks, the files are not corrupted. It runs well after the first try on any folder containing text files right after booting PC, and I ran program on different PCs

0 Kudos
Message 5 of 7
(2,768 Views)

How big is this file?  Could it be that the first time it is slow because it is read directly from the disk and subsequently read from the file cache instead?

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 6 of 7
(2,751 Views)

The files are usually between 5MB - 50MB. But as seen in the vi, I only extract the first KB out of the file. 

That is what I assumed myself, but there are still some instances I re-boot my PC and run the vi and it runs under a second.

0 Kudos
Message 7 of 7
(2,730 Views)