Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. ATL / WTL / STL
  4. Time of reading text file

Time of reading text file

Scheduled Pinned Locked Moved ATL / WTL / STL
adobeperformancequestion
9 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    econy
    wrote on last edited by
    #1

    Hi, I wrote a program in Windows CE platform, CPU is ARM 427MHZ. when program read a text file(size about 700KB,1000 lines) in Flash memory, it needs about 25 seconds to load the file. is there a means to decrease the reading time?

    file.Open(fileName,CFile::typeBinary | CFile::modeRead);
    while ( UNReadString(&file,strLine) ) {
    //strLine.TrimLeft(); TrimRight(); N
    strLine.Trim();

    	strNum  = strLine.Tokenize(TEXT("\\t"),tokenPos);	
    	strEng = strLine.Tokenize(TEXT("\\t"),tokenPos);	//Get English text
    	strCh  = strLine.Tokenize(TEXT("\\t"),tokenPos);	
    	strRus = strLine.Tokenize(TEXT("\\t"),tokenPos);
                
        handleStr();
        tokenPos = 0;
    

    }

    BOOL UNReadString(CFile *iFile, CString &strReturn)
    {
    TCHAR tc;
    CString strBuff = _T("");
    strReturn = _T("");

    while( ( sizeof(TCHAR) ) == ( iFile->Read(&tc, sizeof(TCHAR))) ) //EOF reached?
    {
    	strBuff = tc;
    
    	if(\_T("\\n") != strBuff) {
    		strReturn += strBuff;
    	}
    	else {
    		return TRUE;	//Reached "\\n", 1 line added to strReturn
    	}
    }
    return FALSE;
    

    }

    L A 2 Replies Last reply
    0
    • E econy

      Hi, I wrote a program in Windows CE platform, CPU is ARM 427MHZ. when program read a text file(size about 700KB,1000 lines) in Flash memory, it needs about 25 seconds to load the file. is there a means to decrease the reading time?

      file.Open(fileName,CFile::typeBinary | CFile::modeRead);
      while ( UNReadString(&file,strLine) ) {
      //strLine.TrimLeft(); TrimRight(); N
      strLine.Trim();

      	strNum  = strLine.Tokenize(TEXT("\\t"),tokenPos);	
      	strEng = strLine.Tokenize(TEXT("\\t"),tokenPos);	//Get English text
      	strCh  = strLine.Tokenize(TEXT("\\t"),tokenPos);	
      	strRus = strLine.Tokenize(TEXT("\\t"),tokenPos);
                  
          handleStr();
          tokenPos = 0;
      

      }

      BOOL UNReadString(CFile *iFile, CString &strReturn)
      {
      TCHAR tc;
      CString strBuff = _T("");
      strReturn = _T("");

      while( ( sizeof(TCHAR) ) == ( iFile->Read(&tc, sizeof(TCHAR))) ) //EOF reached?
      {
      	strBuff = tc;
      
      	if(\_T("\\n") != strBuff) {
      		strReturn += strBuff;
      	}
      	else {
      		return TRUE;	//Reached "\\n", 1 line added to strReturn
      	}
      }
      return FALSE;
      

      }

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      econy wrote:

      file.Open(fileName,CFile::typeBinary | CFile::modeRead);

      Why do you open a textfile in binary mode? You will also find that your use of Trim and Tokenize on each line will add considerably to the time.

      E 1 Reply Last reply
      0
      • L Lost User

        econy wrote:

        file.Open(fileName,CFile::typeBinary | CFile::modeRead);

        Why do you open a textfile in binary mode? You will also find that your use of Trim and Tokenize on each line will add considerably to the time.

        E Offline
        E Offline
        econy
        wrote on last edited by
        #3

        Since there are east asian words in the file, and I try to comment tokenize block, no update

        L 1 Reply Last reply
        0
        • E econy

          Since there are east asian words in the file, and I try to comment tokenize block, no update

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          What does UNReadString do, I cannot find a definition for it?

          E 1 Reply Last reply
          0
          • L Lost User

            What does UNReadString do, I cannot find a definition for it?

            E Offline
            E Offline
            econy
            wrote on last edited by
            #5

            had added code for:

            UNReadString(CFile *iFile, CString &strReturn)

            L 1 Reply Last reply
            0
            • E econy

              had added code for:

              UNReadString(CFile *iFile, CString &strReturn)

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Sorry, I was not clear; I meant that I could not find a definition for that function in MSDN, so I do not know what it does. Is this a standard part of WindowsCE and if so where is the documentation for it?

              E 1 Reply Last reply
              0
              • L Lost User

                Sorry, I was not clear; I meant that I could not find a definition for that function in MSDN, so I do not know what it does. Is this a standard part of WindowsCE and if so where is the documentation for it?

                E Offline
                E Offline
                econy
                wrote on last edited by
                #7

                It is not a Wince or Windows function. I wrote it myself.

                L 1 Reply Last reply
                0
                • E econy

                  It is not a Wince or Windows function. I wrote it myself.

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  Then that may well be the place where all your time is being used up.

                  1 Reply Last reply
                  0
                  • E econy

                    Hi, I wrote a program in Windows CE platform, CPU is ARM 427MHZ. when program read a text file(size about 700KB,1000 lines) in Flash memory, it needs about 25 seconds to load the file. is there a means to decrease the reading time?

                    file.Open(fileName,CFile::typeBinary | CFile::modeRead);
                    while ( UNReadString(&file,strLine) ) {
                    //strLine.TrimLeft(); TrimRight(); N
                    strLine.Trim();

                    	strNum  = strLine.Tokenize(TEXT("\\t"),tokenPos);	
                    	strEng = strLine.Tokenize(TEXT("\\t"),tokenPos);	//Get English text
                    	strCh  = strLine.Tokenize(TEXT("\\t"),tokenPos);	
                    	strRus = strLine.Tokenize(TEXT("\\t"),tokenPos);
                                
                        handleStr();
                        tokenPos = 0;
                    

                    }

                    BOOL UNReadString(CFile *iFile, CString &strReturn)
                    {
                    TCHAR tc;
                    CString strBuff = _T("");
                    strReturn = _T("");

                    while( ( sizeof(TCHAR) ) == ( iFile->Read(&tc, sizeof(TCHAR))) ) //EOF reached?
                    {
                    	strBuff = tc;
                    
                    	if(\_T("\\n") != strBuff) {
                    		strReturn += strBuff;
                    	}
                    	else {
                    		return TRUE;	//Reached "\\n", 1 line added to strReturn
                    	}
                    }
                    return FALSE;
                    

                    }

                    A Offline
                    A Offline
                    Aescleal
                    wrote on last edited by
                    #9

                    The first thing you've got to do is work out whether it's I/O bound or whether it's the data processing that's slowing things down. You might find that CFile isn't particularly well tuned for reading from flash and not buffering enough. If it turns out that it's the I/O that's causing the problem find the lowest level function you can call and see what the raw I/O speed of your device is for a range of buffer sizes and then implement something that hits the sweet spot in terms of buffer size. It's a shame you're using MFC classes and not standard library ones as it's a lot easier to replace the underlying buffering and I/O mechanism, but such is life! Another thing might be to try reading more data in your while loop (say 512 characters at a time) and manually parcelling out the data rather than letting CFile::Read do it. If it turns out that the I/O is fast enough then have a look at what you're doing with the data. If you've got a lot of string handling you might find loads of temporaries flying about (especially if you're using VC++ 2008 and earlier) and there's loads of hidden memory manipulation that's slowing things down. In that case look at reducing the number of temporaries you need by reusing objects and expoiting things like NRVO. Anyway, the main thing though is to find out where the bottle neck is then do something about it.

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups