Best way to acess external config data (load mat file vs import data vs fscanf etc. )

조회 수: 39 (최근 30일)
Greetings, I need to store some external parameters in a configuration file (not more than 50 lines). It is not yet defined how many subfunction will need to have access to it but the overall speed will be important. The whole application will be compiled in the end.
I found multiple ways to do this but I am not sure what is the best way: I could load a mat file, read an ascii txt file, a csv and so on (and all this with multiple possibilities).
What is the best (most efficient) way to do this ?
Thanks.
  댓글 수: 5
Mathieu
Mathieu 2014년 6월 17일
Thanks a lot!
I also intuitively thought importdata would be slow, but for some weird reason associated it with the speed of "load" that you implied. It makes complete sense this way.
I use fread/fwrite with virtual com ports but have no idea how to use that with local files. Anyhow, I don't think it is worth to investigate now.
I'll start with a load and will switch to fscanf if needed.
Thanks again for the support.
dpb
dpb 2014년 6월 17일
The biggest difference in speed between the classes is whether they're formatted or unformatted files. The overhead for formatted files is first there's many more bytes/numeric value and secondly it takes compute-time to do the conversion from/to internal storage to the ASCII representation.
For formatted files the higher-level, more convenient forms TMW supplies have all the extra processing and logic built into them that make them more convenient to use but that also comes at a price of far more complexity in the processing. load is slightly more complex than a pure stream of bytes owing to the fact it also saves the structure and the information associated with the variable(s) whereas all of that is your responsibility if you simply write an array as the byte stream.
Similarly, if use fscanf by itself, all the formatting and structure in the file is written explicitly so there's no additional internal logic. If you use one of the more convenient forms then they eventually get down to the final call to the i/o but they have (a varying amount of) flexibility built in so again, that costs something in performance in payback for the convenience (there is no free lunch).
OTOH, for the size of the data you're talking about, I'll reemphasize that write the code for ease of maintainability and clarity of expression first; the amount of data you're talking about is so minimal as to be of no concern for execution time or storage space (again, presuming the avoidance of doing the same thing over and over and over...).

댓글을 달려면 로그인하십시오.

채택된 답변

Mathieu
Mathieu 2014년 6월 17일
The following comment pretty much answers my question:

추가 답변 (1개)

Pritesh Shah
Pritesh Shah 2014년 6월 17일
I think, You may try tic and toc command to find out optimal solution for your case.

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by