<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'Reading a large file' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'Reading a large file' posted on the 'Delphi beginners' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Sat, 25 May 2013 05:06:50 -0700</pubDate>
    <lastBuildDate>Sat, 25 May 2013 05:06:50 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>Reading a large file</title>
      <link>http://www.programmersheaven.com/mb/Delphi/372837/372837/reading-a-large-file/</link>
      <description>I'm trying to open up a large text file (180mb) with +/-500 000 records inside. I have to process each line and insert it into my DB when it has passes the validations. The problem is that is takes 8rec/sec to process which means it takes a couple of hours to do the lot. Can anyone help me with a faster/efficient way of reading files?&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/Delphi/372837/372837/reading-a-large-file/</guid>
      <pubDate>Mon, 23 Jun 2008 03:59:38 -0700</pubDate>
      <category>Delphi beginners</category>
    </item>
    <item>
      <title>Re: Reading a large file</title>
      <link>http://www.programmersheaven.com/mb/Delphi/372837/372842/re-reading-a-large-file/#372842</link>
      <description>: I'm trying to open up a large text file (180mb) with +/-500 000 &lt;br /&gt;
: records inside. I have to process each line and insert it into my DB &lt;br /&gt;
: when it has passes the validations. The problem is that is takes &lt;br /&gt;
: 8rec/sec to process which means it takes a couple of hours to do the &lt;br /&gt;
: lot. Can anyone help me with a faster/efficient way of reading files?&lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
I'm more inclined to suspect the validation or the insert statements as the guilty party. Reading a text-file line by line is quite fast. For one of my projects I had to read and parse 40000 lines (~7 MB), which took about 30 seconds. Expanding that I would suspect that reading your file should take about 10 mins.&lt;br /&gt;
You should test that using only the read part. Then adding the validation and finally adding only the insertions (with some general exception handling). This should give you a clear idea where the lack of speed comes from.</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/Delphi/372837/372842/re-reading-a-large-file/#372842</guid>
      <pubDate>Mon, 23 Jun 2008 10:40:15 -0700</pubDate>
      <category>Delphi beginners</category>
    </item>
    <item>
      <title>Re: Reading a large file</title>
      <link>http://www.programmersheaven.com/mb/Delphi/372837/372918/re-reading-a-large-file/#372918</link>
      <description>: : I'm trying to open up a large text file (180mb) with +/-500 000 &lt;br /&gt;
: : records inside. I have to process each line and insert it into my DB &lt;br /&gt;
: : when it has passes the validations. The problem is that is takes &lt;br /&gt;
: : 8rec/sec to process which means it takes a couple of hours to do the &lt;br /&gt;
: : lot. Can anyone help me with a faster/efficient way of reading files?&lt;br /&gt;
: : &lt;br /&gt;
: : &lt;br /&gt;
: I'm more inclined to suspect the validation or the insert statements &lt;br /&gt;
: as the guilty party. Reading a text-file line by line is quite fast. &lt;br /&gt;
: For one of my projects I had to read and parse 40000 lines (~7 MB), &lt;br /&gt;
: which took about 30 seconds. Expanding that I would suspect that &lt;br /&gt;
: reading your file should take about 10 mins.&lt;br /&gt;
: You should test that using only the read part. Then adding the &lt;br /&gt;
: validation and finally adding only the insertions (with some general &lt;br /&gt;
: exception handling). This should give you a clear idea where the &lt;br /&gt;
: lack of speed comes from.&lt;br /&gt;
&lt;br /&gt;
Hi zibadian, thanks for the reply. I took your advice and uncommented all my validation &amp;amp; insert code. After 10min I was on record 30648 which means that my validations &amp;amp; inserts are slow, but still, the file reading is still way too slow. I'm using the assignfile &amp;amp; readln procedure. I need a method in which I can speed this up. Any suggestions on how I can achieve this? &lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/Delphi/372837/372918/re-reading-a-large-file/#372918</guid>
      <pubDate>Thu, 26 Jun 2008 04:43:43 -0700</pubDate>
      <category>Delphi beginners</category>
    </item>
    <item>
      <title>Re: Reading a large file</title>
      <link>http://www.programmersheaven.com/mb/Delphi/372837/372933/re-reading-a-large-file/#372933</link>
      <description>: : : I'm trying to open up a large text file (180mb) with +/-500 000 &lt;br /&gt;
: : : records inside. I have to process each line and insert it into my DB &lt;br /&gt;
: : : when it has passes the validations. The problem is that is takes &lt;br /&gt;
: : : 8rec/sec to process which means it takes a couple of hours to do the &lt;br /&gt;
: : : lot. Can anyone help me with a faster/efficient way of reading files?&lt;br /&gt;
: : : &lt;br /&gt;
: : : &lt;br /&gt;
: : I'm more inclined to suspect the validation or the insert statements &lt;br /&gt;
: : as the guilty party. Reading a text-file line by line is quite fast. &lt;br /&gt;
: : For one of my projects I had to read and parse 40000 lines (~7 MB), &lt;br /&gt;
: : which took about 30 seconds. Expanding that I would suspect that &lt;br /&gt;
: : reading your file should take about 10 mins.&lt;br /&gt;
: : You should test that using only the read part. Then adding the &lt;br /&gt;
: : validation and finally adding only the insertions (with some general &lt;br /&gt;
: : exception handling). This should give you a clear idea where the &lt;br /&gt;
: : lack of speed comes from.&lt;br /&gt;
: &lt;br /&gt;
: Hi zibadian, thanks for the reply. I took your advice and &lt;br /&gt;
: uncommented all my validation &amp;amp; insert code. After 10min I was on &lt;br /&gt;
: record 30648 which means that my validations &amp;amp; inserts are slow, but &lt;br /&gt;
: still, the file reading is still way too slow. I'm using the &lt;br /&gt;
: assignfile &amp;amp; readln procedure. I need a method in which I can speed &lt;br /&gt;
: this up. Any suggestions on how I can achieve this? &lt;br /&gt;
: &lt;br /&gt;
You could try to read the file into a TStrings object. Then use that object to parse the records.&lt;br /&gt;
Another option is to use a TMemoryStream to store the entire file in, and then parse that to read the records. This is more difficult, because there's no implicit function/method to read a line from a TMemoryStream.&lt;br /&gt;
If those two options don't work, then you'll need faster hardware.</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/Delphi/372837/372933/re-reading-a-large-file/#372933</guid>
      <pubDate>Thu, 26 Jun 2008 10:59:39 -0700</pubDate>
      <category>Delphi beginners</category>
    </item>
    <item>
      <title>Re: Reading a large file</title>
      <link>http://www.programmersheaven.com/mb/Delphi/372837/372946/re-reading-a-large-file/#372946</link>
      <description>: : : : I'm trying to open up a large text file (180mb) with +/-500 000 &lt;br /&gt;
: : : : records inside. I have to process each line and insert it into my DB &lt;br /&gt;
: : : : when it has passes the validations. The problem is that is takes &lt;br /&gt;
: : : : 8rec/sec to process which means it takes a couple of hours to do the &lt;br /&gt;
: : : : lot. Can anyone help me with a faster/efficient way of reading files?&lt;br /&gt;
: : : : &lt;br /&gt;
: : : : &lt;br /&gt;
: : : I'm more inclined to suspect the validation or the insert statements &lt;br /&gt;
: : : as the guilty party. Reading a text-file line by line is quite fast. &lt;br /&gt;
: : : For one of my projects I had to read and parse 40000 lines (~7 MB), &lt;br /&gt;
: : : which took about 30 seconds. Expanding that I would suspect that &lt;br /&gt;
: : : reading your file should take about 10 mins.&lt;br /&gt;
: : : You should test that using only the read part. Then adding the &lt;br /&gt;
: : : validation and finally adding only the insertions (with some general &lt;br /&gt;
: : : exception handling). This should give you a clear idea where the &lt;br /&gt;
: : : lack of speed comes from.&lt;br /&gt;
: : &lt;br /&gt;
: : Hi zibadian, thanks for the reply. I took your advice and &lt;br /&gt;
: : uncommented all my validation &amp;amp; insert code. After 10min I was on &lt;br /&gt;
: : record 30648 which means that my validations &amp;amp; inserts are slow, but &lt;br /&gt;
: : still, the file reading is still way too slow. I'm using the &lt;br /&gt;
: : assignfile &amp;amp; readln procedure. I need a method in which I can speed &lt;br /&gt;
: : this up. Any suggestions on how I can achieve this? &lt;br /&gt;
: : &lt;br /&gt;
: You could try to read the file into a TStrings object. Then use that &lt;br /&gt;
: object to parse the records.&lt;br /&gt;
: Another option is to use a TMemoryStream to store the entire file &lt;br /&gt;
: in, and then parse that to read the records. This is more difficult, &lt;br /&gt;
: because there's no implicit function/method to read a line from a &lt;br /&gt;
: TMemoryStream.&lt;br /&gt;
: If those two options don't work, then you'll need faster hardware.&lt;br /&gt;
&lt;br /&gt;
I already have tried reading it into a TString object, but the speed is roughly the same. I will try to use the TMemoryStream object and see if I have any success with it and will let you know.&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/Delphi/372837/372946/re-reading-a-large-file/#372946</guid>
      <pubDate>Thu, 26 Jun 2008 23:22:17 -0700</pubDate>
      <category>Delphi beginners</category>
    </item>
    <item>
      <title>Re: Reading a large file</title>
      <link>http://www.programmersheaven.com/mb/Delphi/372837/382076/re-reading-a-large-file/#382076</link>
      <description>Use TMemoryStream, I can read 700mb of smalls files (3kb each) in 3 seconds.&lt;br /&gt;
Is more fast read all file and take in memory than you read 3kbytes from HD each time that you want the next line.&lt;br /&gt;
I don't guess hard to find the lines in TMemoryStream, after load, you can create a function&lt;br /&gt;
&lt;br /&gt;
function readLineFromMemory(x: TMemoryStream): string;&lt;br /&gt;
var &lt;br /&gt;
 s: string;&lt;br /&gt;
 c: char;&lt;br /&gt;
 i: integer;&lt;br /&gt;
begin&lt;br /&gt;
 i := x.position;&lt;br /&gt;
 while (I &amp;lt; x.size) do&lt;br /&gt;
  begin&lt;br /&gt;
  x.read(c, size_of(c));&lt;br /&gt;
  inc(I);&lt;br /&gt;
  s := s + c;&lt;br /&gt;
  if c = #13 then break;&lt;br /&gt;
  end;&lt;br /&gt;
 result := s;&lt;br /&gt;
end;&lt;br /&gt;
&lt;br /&gt;
I don't tested it.&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/Delphi/372837/382076/re-reading-a-large-file/#382076</guid>
      <pubDate>Thu, 20 Nov 2008 09:01:55 -0700</pubDate>
      <category>Delphi beginners</category>
    </item>
  </channel>
</rss>