Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #13340 > unrolled thread
| Started by | pozz <pozzugno@gmail.com> |
|---|---|
| First post | 2011-11-14 16:02 -0800 |
| Last post | 2011-11-16 13:50 -0800 |
| Articles | 20 on this page of 32 — 21 participants |
Back to article view | Back to comp.lang.c
Deleting first N lines from a text file pozz <pozzugno@gmail.com> - 2011-11-14 16:02 -0800
Re: Deleting first N lines from a text file Roberto Waltman <usenet@rwaltman.com> - 2011-11-14 19:21 -0500
Re: Deleting first N lines from a text file Acid Washed China Blue Jeans <chine.bleu@yahoo.com> - 2011-11-14 16:31 -0800
Re: Deleting first N lines from a text file blp@cs.stanford.edu (Ben Pfaff) - 2011-11-14 16:36 -0800
Re: Deleting first N lines from a text file Roberto Waltman <usenet@rwaltman.com> - 2011-11-14 20:10 -0500
Re: Deleting first N lines from a text file Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2011-11-16 11:04 +0200
Re: Deleting first N lines from a text file gordonb.3hlvm@burditt.org (Gordon Burditt) - 2011-11-14 18:53 -0600
Re: Deleting first N lines from a text file Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-11-14 22:06 -0500
Re: Deleting first N lines from a text file Giuseppe <giuseppe.modugno@gmail.com> - 2011-11-15 16:57 -0800
Re: Deleting first N lines from a text file Keith Thompson <kst-u@mib.org> - 2011-11-15 17:50 -0800
Re: Deleting first N lines from a text file pozz <pozzugno@gmail.com> - 2011-11-15 23:11 -0800
Re: Deleting first N lines from a text file jgharston <jgh@arcade.demon.co.uk> - 2011-11-16 04:11 -0800
Re: Deleting first N lines from a text file Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-11-15 21:48 -0500
Re: Deleting first N lines from a text file pozz <pozzugno@gmail.com> - 2011-11-15 23:14 -0800
Re: Deleting first N lines from a text file "BartC" <bc@freeuk.com> - 2011-11-16 14:26 +0000
Re: Deleting first N lines from a text file Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-11-16 21:32 -0500
Re: Deleting first N lines from a text file Ian Collins <ian-news@hotmail.com> - 2011-11-17 15:43 +1300
Re: Deleting first N lines from a text file "BartC" <bc@freeuk.com> - 2011-11-17 10:35 +0000
Re: Deleting first N lines from a text file Dr Nick <3-nospam@temporary-address.org.uk> - 2011-12-16 07:05 +0000
Re: Deleting first N lines from a text file Robert Wessel <robertwessel2@yahoo.com> - 2011-11-16 22:46 -0600
Re: Deleting first N lines from a text file gordonb.pa5u0@burditt.org (Gordon Burditt) - 2011-11-16 16:28 -0600
Re: Deleting first N lines from a text file Kaz Kylheku <kaz@kylheku.com> - 2011-11-16 22:53 +0000
Re: Deleting first N lines from a text file gordonb.z5i2o@burditt.org (Gordon Burditt) - 2011-11-16 18:34 -0600
Re: Deleting first N lines from a text file jacob navia <jacob@spamsink.net> - 2011-11-15 12:48 +0100
Re: Deleting first N lines from a text file "-.-" <none@none.none> - 2011-11-16 14:01 +0100
Re: Deleting first N lines from a text file jacob navia <jacob@spamsink.net> - 2011-11-16 14:44 +0100
Re: Deleting first N lines from a text file tom st denis <tom@iahu.ca> - 2011-11-17 10:43 -0800
Re: Deleting first N lines from a text file jt@toerring.de (Jens Thoms Toerring) - 2011-11-18 23:12 +0000
Re: Deleting first N lines from a text file jgharston <jgh@arcade.demon.co.uk> - 2011-11-16 06:42 -0800
Re: Deleting first N lines from a text file jgharston <jgh@arcade.demon.co.uk> - 2011-11-16 07:43 -0800
Re: Deleting first N lines from a text file Keith Thompson <kst-u@mib.org> - 2011-11-16 11:13 -0800
Re: Deleting first N lines from a text file jgharston <jgh@arcade.demon.co.uk> - 2011-11-16 13:50 -0800
Page 1 of 2 [1] 2 Next page →
| From | pozz <pozzugno@gmail.com> |
|---|---|
| Date | 2011-11-14 16:02 -0800 |
| Subject | Deleting first N lines from a text file |
| Message-ID | <469add1a-0497-4746-9c52-6c775ecd53d9@u5g2000vbd.googlegroups.com> |
I want to delete the first N lines from a file text. I imagine two
approaches:
- use a temporary file to copy the last lines only
- use the same file to move characters starting from N+1 line to the
beginning
The temporary file could be more complex to write (at last I have to
delete the original file and rename the temporary file), but at any
moment I have a coherent text file. So this approach is safe if the
application crashes during the deleting process. If the application
crashes just after deleting the original text file but before renaming
the temporary file, during initialization I can detect this situation
and proceed with the renaming.
The second approach is simpler, but leaves a malformed text file on
the filesystem if the application crashes during the deleting process.
What do you think about those thoughts? Do you agree with me?
My "deleting first N lines" function is:
int text_delete(unsigned int N) {
FILE *f;
FILE *ftmp;
int c;
f = fopen(filename, "rt");
ftmp = fopen(tmpfilename, "wt");
if ((f == NULL) || (ftmp == NULL)) {
return -1;
}
while((c = fgetc(f)) != EOF) {
if ((char)c == '\n') {
if (--N == 0) break;
}
}
while((c = fgetc(f)) != EOF) {
fputc(c, ftmp);
}
fclose(f);
fclose(ftmp);
if (remove(filename) < 0) return -1;
if (rename(tmpfilename, filename) < 0) return -1;
return 0;
}
At initialization I try to open the text file or the temporary file;
int text_init(void) {
FILE *f;
f = fopen(filename, "rt");
if (f == NULL) {
/* Does the temporary file exist? */
f = fopen(tmpfilename, "rt");
if (f != NULL) {
/* Yes!, recover temporary file */
fclose(f);
if (rename(tmpfilename, filename) < 0) return -1;
} else {
/* Create an empty log file... */
f = fopen(filename, "wt");
if (f == NULL) return -1;
fclose(f);
}
} else {
fclose(f);
}
return 0;
}
[toc] | [next] | [standalone]
| From | Roberto Waltman <usenet@rwaltman.com> |
|---|---|
| Date | 2011-11-14 19:21 -0500 |
| Message-ID | <mub3c71nfmmvbvmcbndc29saadjo64t72e@4ax.com> |
| In reply to | #13340 |
pozz wrote: >I want to delete the first N lines from a file text. >... >The second approach is simpler,... >... >What do you think about those thoughts? Only that the second approach is not simpler. Also, depending on the underlying OS, it may not be possible to read from and write to the same file as you propose. -- Roberto Waltman [ Please reply to the group, return address is invalid ]
[toc] | [prev] | [next] | [standalone]
| From | Acid Washed China Blue Jeans <chine.bleu@yahoo.com> |
|---|---|
| Date | 2011-11-14 16:31 -0800 |
| Message-ID | <chine.bleu-EFA4DB.16310514112011@news.eternal-september.org> |
| In reply to | #13341 |
In article <mub3c71nfmmvbvmcbndc29saadjo64t72e@4ax.com>, Roberto Waltman <usenet@rwaltman.com> wrote: > pozz wrote: > >I want to delete the first N lines from a file text. > >... > >The second approach is simpler,... > >... > >What do you think about those thoughts? > > Only that the second approach is not simpler. > Also, depending on the underlying OS, it may not be possible to read > from and write to the same file as you propose. Fopen with "r+". If fopen succeeds, the library has promised you you are allowed to read and write an existing file. -- White folks think they're at the top, | Faded, patched, secret so tight... ask any proud white male. | I'm whoever you want me to be. A million years of evolution, | Annoying Usenet one post at a time. and we get Danny Quayle. | At least I can stay in character.
[toc] | [prev] | [next] | [standalone]
| From | blp@cs.stanford.edu (Ben Pfaff) |
|---|---|
| Date | 2011-11-14 16:36 -0800 |
| Message-ID | <87fwhqql0s.fsf@blp.benpfaff.org> |
| In reply to | #13342 |
Acid Washed China Blue Jeans <chine.bleu@yahoo.com> writes:
> In article <mub3c71nfmmvbvmcbndc29saadjo64t72e@4ax.com>,
> Roberto Waltman <usenet@rwaltman.com> wrote:
>
>> pozz wrote:
>> >I want to delete the first N lines from a file text.
>> >...
>> >The second approach is simpler,...
>> >...
>> >What do you think about those thoughts?
>>
>> Only that the second approach is not simpler.
>> Also, depending on the underlying OS, it may not be possible to read
>> from and write to the same file as you propose.
>
> Fopen with "r+". If fopen succeeds, the library has promised
> you you are allowed to read and write an existing file.
However, writing in a text file may truncate it, see 7.19.3
"Files":
Whether a write on a text stream causes the associated file
to be truncated beyond that point is implementation-defined.
--
int main(void){char p[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.\
\n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}
[toc] | [prev] | [next] | [standalone]
| From | Roberto Waltman <usenet@rwaltman.com> |
|---|---|
| Date | 2011-11-14 20:10 -0500 |
| Message-ID | <cie3c755k7lon2o729q2atqj0chm13e34l@4ax.com> |
| In reply to | #13342 |
Acid Washed China Blue Jeans wrote: >Fopen with "r+". If fopen succeeds, the library has promised you you are allowed >to read and write an existing file. In the general case, a write may truncate the file at the end of the written data, so it may be OK to read from a location before the last location written, but not after it. And there may be environments in which fopen(..., "r+") always fails. -- Roberto Waltman [ Please reply to the group, return address is invalid ]
[toc] | [prev] | [next] | [standalone]
| From | Phil Carmody <thefatphil_demunged@yahoo.co.uk> |
|---|---|
| Date | 2011-11-16 11:04 +0200 |
| Message-ID | <87aa7wbfq9.fsf@bazspaz.fatphil.org> |
| In reply to | #13342 |
Acid Washed China Blue Jeans <chine.bleu@yahoo.com> writes: > In article <mub3c71nfmmvbvmcbndc29saadjo64t72e@4ax.com>, > Roberto Waltman <usenet@rwaltman.com> wrote: > > pozz wrote: > > >I want to delete the first N lines from a file text. > > >... > > >The second approach is simpler,... > > >... > > >What do you think about those thoughts? > > > > Only that the second approach is not simpler. > > Also, depending on the underlying OS, it may not be possible to read > > from and write to the same file as you propose. > > Fopen with "r+". If fopen succeeds, the library has promised you you are allowed > to read and write an existing file. Being allowed to write to it at the point that you open the file doesn't mean that it's possible to write to the file at any point later in time. Think wire-cutters. Phil -- Unix is simple. It just takes a genius to understand its simplicity -- Dennis Ritchie (1941-2011), Unix Co-Creator
[toc] | [prev] | [next] | [standalone]
| From | gordonb.3hlvm@burditt.org (Gordon Burditt) |
|---|---|
| Date | 2011-11-14 18:53 -0600 |
| Message-ID | <_-qdnTc5rPRyKlzTnZ2dnUVZ_uidnZ2d@posted.internetamerica> |
| In reply to | #13340 |
> I want to delete the first N lines from a file text. I imagine two > approaches: > - use a temporary file to copy the last lines only > - use the same file to move characters starting from N+1 line to the > beginning You forgot something here: for the second method, you need to shrink the file by the length of the first N lines, or you end up with extra stuff at the end of the file (you might make the program reading the file recognize it and ignore it). There is no portable way to shrink a file to a size other than zero. > The temporary file could be more complex to write (at last I have to > delete the original file and rename the temporary file), but at any > moment I have a coherent text file. So this approach is safe if the > application crashes during the deleting process. If the application > crashes just after deleting the original text file but before renaming > the temporary file, during initialization I can detect this situation > and proceed with the renaming. > The second approach is simpler, but leaves a malformed text file on > the filesystem if the application crashes during the deleting process. IMHO, the second method *always* leaves extra garbage at the end of the text file (assuming N > 0), unless you figure out some way to remove it (unportable) or flag it as meaningless (e.g. set it to a line consisting of all spaces or something). There is no documented mode for fopen "rt" or "wt".
[toc] | [prev] | [next] | [standalone]
| From | Eric Sosman <esosman@ieee-dot-org.invalid> |
|---|---|
| Date | 2011-11-14 22:06 -0500 |
| Message-ID | <j9sl02$j6f$1@dont-email.me> |
| In reply to | #13340 |
On 11/14/2011 7:02 PM, pozz wrote:
> I want to delete the first N lines from a file text. I imagine two
> approaches:
> - use a temporary file to copy the last lines only
Do this.
> - use the same file to move characters starting from N+1 line to the
> beginning
Don't do this.
> The temporary file could be more complex to write (at last I have to
> delete the original file and rename the temporary file), but at any
> moment I have a coherent text file. So this approach is safe if the
> application crashes during the deleting process. If the application
> crashes just after deleting the original text file but before renaming
> the temporary file, during initialization I can detect this situation
> and proceed with the renaming.
>
> The second approach is simpler, but leaves a malformed text file on
> the filesystem if the application crashes during the deleting process.
>
> What do you think about those thoughts? Do you agree with me?
No, not at all. One problem with your supposedly simpler
solution: How do you tell subsequent readers of the file that they
should stop before reaching the end? Observe that <stdio.h> offers
no way to shorten an existing file to any length other than zero.
--
Eric Sosman
esosman@ieee-dot-org.invalid
[toc] | [prev] | [next] | [standalone]
| From | Giuseppe <giuseppe.modugno@gmail.com> |
|---|---|
| Date | 2011-11-15 16:57 -0800 |
| Message-ID | <41199f8e-82e7-4b90-8b8a-c79dd437b1ec@p1g2000yqh.googlegroups.com> |
| In reply to | #13351 |
On 15 Nov, 04:06, Eric Sosman <esos...@ieee-dot-org.invalid> wrote: > > What do you think about those thoughts? Do you agree with me? > > No, not at all. One problem with your supposedly simpler > solution: How do you tell subsequent readers of the file that they > should stop before reaching the end? Observe that <stdio.h> offers > no way to shorten an existing file to any length other than zero. Ok, I implemented the "temporary file" solution and it works well. The only disadvantage is time: when the file is big (1000 lines of about 50 bytes each), the time to delete the first line could be very high. Do you think the process could be reduced launching an external script (for example, 'head' based) with system()? If I redirect the output to the original filename I could avoid the time consuming process of copying the original to the temporary file.
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Date | 2011-11-15 17:50 -0800 |
| Message-ID | <lny5vgzvgm.fsf@nuthaus.mib.org> |
| In reply to | #13449 |
Giuseppe <giuseppe.modugno@gmail.com> writes:
> On 15 Nov, 04:06, Eric Sosman <esos...@ieee-dot-org.invalid> wrote:
>> > What do you think about those thoughts? Do you agree with me?
>>
>> No, not at all. One problem with your supposedly simpler
>> solution: How do you tell subsequent readers of the file that they
>> should stop before reaching the end? Observe that <stdio.h> offers
>> no way to shorten an existing file to any length other than zero.
>
> Ok, I implemented the "temporary file" solution and it works well.
> The only disadvantage is time: when the file is big (1000 lines of
> about 50 bytes each), the time to delete the first line could be very
> high.
A text file of 1000 lines of 50 bytes each really isn't all that big.
The time to copy and rename it probably won't even be noticeable.
> Do you think the process could be reduced launching an external script
> (for example, 'head' based) with system()? If I redirect the output
> to the original filename I could avoid the time consuming process of
> copying the original to the temporary file.
The behavior of external program is outside the scope of the C language.
(But I'll mention that on Unix-like systems, running a command with its
input and output directed to the same file can cause serious problems;
it can easily end up reading a partially modified version of the file
instead of the original. And even if it works, it's likely going to be
doing the same thing you would have done in your program.)
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
[toc] | [prev] | [next] | [standalone]
| From | pozz <pozzugno@gmail.com> |
|---|---|
| Date | 2011-11-15 23:11 -0800 |
| Message-ID | <6e16893f-ba8f-482f-b15c-c73c22fb1a5e@k26g2000yqd.googlegroups.com> |
| In reply to | #13451 |
On 16 Nov, 02:50, Keith Thompson <ks...@mib.org> wrote: > Giuseppe <giuseppe.modu...@gmail.com> writes: > > Ok, I implemented the "temporary file" solution and it works well. > > The only disadvantage is time: when the file is big (1000 lines of > > about 50 bytes each), the time to delete the first line could be very > > high. > > A text file of 1000 lines of 50 bytes each really isn't all that big. > The time to copy and rename it probably won't even be noticeable. It takes about 100ms to finish the shrink procedure. It's not a long time on a desktop PC, but I'm working on ambedded Linux based on ARM9 processor. The slowest part of my application is this. Anyway I'm thinking if there are some simple improvements to reduce the time taken by this task. > > Do you think the process could be reduced launching an external script > > (for example, 'head' based) with system()? If I redirect the output > > to the original filename I could avoid the time consuming process of > > copying the original to the temporary file. > > The behavior of external program is outside the scope of the C language. Oh, I now, I was asking for on "off-topic" opinion :-) > (But I'll mention that on Unix-like systems, running a command with its > input and output directed to the same file can cause serious problems; > it can easily end up reading a partially modified version of the file > instead of the original. And even if it works, it's likely going to be > doing the same thing you would have done in your program.) Ok, I'll not try.
[toc] | [prev] | [next] | [standalone]
| From | jgharston <jgh@arcade.demon.co.uk> |
|---|---|
| Date | 2011-11-16 04:11 -0800 |
| Message-ID | <948bf635-1f91-4187-8868-973532952cb4@l19g2000yqc.googlegroups.com> |
| In reply to | #13462 |
pozz wrote: > It takes about 100ms to finish the shrink procedure. It's not a long > time on a desktop PC, but I'm working on ambedded Linux based on ARM9 > processor. Are you doing it byte by byte? Try buffering it, even chunks of 16 bytes at a time will speed it up significantly. What's the biggest chunk of memory you can claim, use, release without memory fragmentation impacting your program more than acceptably? JGH
[toc] | [prev] | [next] | [standalone]
| From | Eric Sosman <esosman@ieee-dot-org.invalid> |
|---|---|
| Date | 2011-11-15 21:48 -0500 |
| Message-ID | <j9v89c$urd$1@dont-email.me> |
| In reply to | #13449 |
On 11/15/2011 7:57 PM, Giuseppe wrote:
> On 15 Nov, 04:06, Eric Sosman<esos...@ieee-dot-org.invalid> wrote:
>>> What do you think about those thoughts? Do you agree with me?
>>
>> No, not at all. One problem with your supposedly simpler
>> solution: How do you tell subsequent readers of the file that they
>> should stop before reaching the end? Observe that<stdio.h> offers
>> no way to shorten an existing file to any length other than zero.
>
> Ok, I implemented the "temporary file" solution and it works well.
> The
> only disadvantage is time: when the file is big (1000 lines of about
> 50 bytes
> each), the time to delete the first line could be very high.
Fifty K shouldn't take long. Even on a system from forty years
ago it didn't take long. Even on paper tape, for goodness' sake, it
took less than a minute!
For "really big" files (terabytes) copying most of the file from
one place to another could take an unacceptably long time. Also, the
need to find space for a second nearly complete copy could be
troublesome. In such cases you'd be justified in seeking fancier
solutions -- but I sincerely doubt that "slide all those terabytes
a couple hundred positions leftward" would produce a savings. More
likely it would produce a slowdown, plus the risks you've already
mentioned about data loss in the event of an error. No, the fancier
solution would probably involve some kind of an index external to the
file, describing which parts of the file were "live" and which "dead,"
and fancier routines to read just the live parts.
> Do you think the process could be reduced launching an external script
> (for
> example, 'head' based) with system()? If I redirect the output to the
> original
> filename I could avoid the time consuming process of copying the
> original
> to the temporary file.
First, just what do you imagine the "head" program does, hmmm?
However, on the systems I've encountered that provide a "head"
utility and support "redirection," your solution is likely to run
very quickly indeed. And save a lot of disk space, too! (Hint:
Try it yourself: `head <foo.txt >foo.txt', then `ls -l foo.txt',
and then you get to test your backups ...)
But all this is mostly beside the point. You are worried about
the time to copy 50K bytes: Have you *measured* the time? Have you
actually found it to be a problem for your application? Or are you
just imagining monsters under your bed? The fundamental theorem of
all optimization is There Are No Monsters Until You've Measured Them.
--
Eric Sosman
esosman@ieee-dot-org.invalid
[toc] | [prev] | [next] | [standalone]
| From | pozz <pozzugno@gmail.com> |
|---|---|
| Date | 2011-11-15 23:14 -0800 |
| Message-ID | <f06508a1-a424-4bc7-99f6-98e94e6944e6@w7g2000yqc.googlegroups.com> |
| In reply to | #13456 |
On 16 Nov, 03:48, Eric Sosman <esos...@ieee-dot-org.invalid> wrote: > On 11/15/2011 7:57 PM, Giuseppe wrote: > > Ok, I implemented the "temporary file" solution and it works well. > > The > > only disadvantage is time: when the file is big (1000 lines of about > > 50 bytes > > each), the time to delete the first line could be very high. > > Fifty K shouldn't take long. Even on a system from forty years > ago it didn't take long. Even on paper tape, for goodness' sake, it > took less than a minute! 100ms (see my answer to Keith above). It's not too much, but I was thingking about improvements. > For "really big" files (terabytes) copying most of the file from > one place to another could take an unacceptably long time. Also, the > need to find space for a second nearly complete copy could be > troublesome. In such cases you'd be justified in seeking fancier > solutions -- but I sincerely doubt that "slide all those terabytes > a couple hundred positions leftward" would produce a savings. More > likely it would produce a slowdown, plus the risks you've already > mentioned about data loss in the event of an error. No, the fancier > solution would probably involve some kind of an index external to the > file, describing which parts of the file were "live" and which "dead," > and fancier routines to read just the live parts. Ok. > > Do you think the process could be reduced launching an external script > > (for > > example, 'head' based) with system()? If I redirect the output to the > > original > > filename I could avoid the time consuming process of copying the > > original > > to the temporary file. > > First, just what do you imagine the "head" program does, hmmm? > > However, on the systems I've encountered that provide a "head" > utility and support "redirection," your solution is likely to run > very quickly indeed. And save a lot of disk space, too! (Hint: > Try it yourself: `head <foo.txt >foo.txt', then `ls -l foo.txt', > and then you get to test your backups ...) :-) > But all this is mostly beside the point. You are worried about > the time to copy 50K bytes: Have you *measured* the time? Have you > actually found it to be a problem for your application? Or are you > just imagining monsters under your bed? The fundamental theorem of > all optimization is There Are No Monsters Until You've Measured Them.
[toc] | [prev] | [next] | [standalone]
| From | "BartC" <bc@freeuk.com> |
|---|---|
| Date | 2011-11-16 14:26 +0000 |
| Message-ID | <ja0h6r$g5v$1@dont-email.me> |
| In reply to | #13463 |
"pozz" <pozzugno@gmail.com> wrote in message news:f06508a1-a424-4bc7-99f6-98e94e6944e6@w7g2000yqc.googlegroups.com... > On 16 Nov, 03:48, Eric Sosman <esos...@ieee-dot-org.invalid> wrote: >> On 11/15/2011 7:57 PM, Giuseppe wrote: >> > Ok, I implemented the "temporary file" solution and it works well. >> > The >> > only disadvantage is time: when the file is big (1000 lines of about >> > 50 bytes >> > each), the time to delete the first line could be very high. >> >> Fifty K shouldn't take long. Even on a system from forty years >> ago it didn't take long. Even on paper tape, for goodness' sake, it >> took less than a minute! (That's a fast paper tape reader. The last one I used would have taken nearly 3 hours.) > 100ms (see my answer to Keith above). It's not too much, but I was > thingking > about improvements. How long for a file containing ten lines instead of 1000? How long for double the number of lines? That will tell you the overheads involved and the fastest speed achievable. While you're about, how long does it take to create a file, write 50,000 bytes to it (of anything) and close it? And how long to read such a file? Take care when taking measurements, to eliminate the effects of disk-caching. -- Bartc
[toc] | [prev] | [next] | [standalone]
| From | Eric Sosman <esosman@ieee-dot-org.invalid> |
|---|---|
| Date | 2011-11-16 21:32 -0500 |
| Message-ID | <ja1rnu$b6g$1@dont-email.me> |
| In reply to | #13480 |
On 11/16/2011 9:26 AM, BartC wrote:
> "pozz" <pozzugno@gmail.com> wrote in message
> news:f06508a1-a424-4bc7-99f6-98e94e6944e6@w7g2000yqc.googlegroups.com...
>> On 16 Nov, 03:48, Eric Sosman <esos...@ieee-dot-org.invalid> wrote:
>>>[...]
>>> Fifty K shouldn't take long. Even on a system from forty years
>>> ago it didn't take long. Even on paper tape, for goodness' sake, it
>>> took less than a minute!
>
> (That's a fast paper tape reader. The last one I used would have taken
> nearly 3 hours.)
http://www.springerlink.com/content/x42n45gk4811lpq1/ from 1963
describes a "high speed paper tape reader with a maximum speed of
1000 characters per second." 50KB / (1000 B/s) = 50s < one minute.
However, I realize I've erred, and in two ways. First, I've
neglected the time to punch the paper tape, an operation a good
deal slower than reading it. Second, I've overlooked an O(1)
solution: Take the original file, on paper tape, and apply a pair
of scissors to remove the first N lines -- no copying involved,
although there might be some difficulty finding enough "leader"
to feed into the read mechanism next time the data is wanted ...
--
Eric Sosman
esosman@ieee-dot-org.invalid
[toc] | [prev] | [next] | [standalone]
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Date | 2011-11-17 15:43 +1300 |
| Message-ID | <9ijan5Fi5oU19@mid.individual.net> |
| In reply to | #13535 |
On 11/17/11 03:32 PM, Eric Sosman wrote: > On 11/16/2011 9:26 AM, BartC wrote: >> "pozz"<pozzugno@gmail.com> wrote in message >> news:f06508a1-a424-4bc7-99f6-98e94e6944e6@w7g2000yqc.googlegroups.com... >>> On 16 Nov, 03:48, Eric Sosman<esos...@ieee-dot-org.invalid> wrote: >>>> [...] >>>> Fifty K shouldn't take long. Even on a system from forty years >>>> ago it didn't take long. Even on paper tape, for goodness' sake, it >>>> took less than a minute! >> >> (That's a fast paper tape reader. The last one I used would have taken >> nearly 3 hours.) > > http://www.springerlink.com/content/x42n45gk4811lpq1/ from 1963 > describes a "high speed paper tape reader with a maximum speed of > 1000 characters per second." 50KB / (1000 B/s) = 50s< one minute. That modern? The machine that preceded Colossus at Bletchley Park in the early 40s could read paper tape at 1000 characters per second! -- Ian Collins
[toc] | [prev] | [next] | [standalone]
| From | "BartC" <bc@freeuk.com> |
|---|---|
| Date | 2011-11-17 10:35 +0000 |
| Message-ID | <ja2o2e$hsv$1@dont-email.me> |
| In reply to | #13537 |
"Ian Collins" <ian-news@hotmail.com> wrote in message news:9ijan5Fi5oU19@mid.individual.net... > On 11/17/11 03:32 PM, Eric Sosman wrote: >> On 11/16/2011 9:26 AM, BartC wrote: >>> "pozz"<pozzugno@gmail.com> wrote in message >>> news:f06508a1-a424-4bc7-99f6-98e94e6944e6@w7g2000yqc.googlegroups.com... >>>> On 16 Nov, 03:48, Eric Sosman<esos...@ieee-dot-org.invalid> wrote: >>>>> [...] >>>>> Fifty K shouldn't take long. Even on a system from forty years >>>>> ago it didn't take long. Even on paper tape, for goodness' sake, it >>>>> took less than a minute! >>> >>> (That's a fast paper tape reader. The last one I used would have taken >>> nearly 3 hours.) >> >> http://www.springerlink.com/content/x42n45gk4811lpq1/ from 1963 >> describes a "high speed paper tape reader with a maximum speed of >> 1000 characters per second." 50KB / (1000 B/s) = 50s< one minute. > > That modern? The machine that preceded Colossus at Bletchley Park in the > early 40s could read paper tape at 1000 characters per second! I've seen Colossus itself in action (the replica, not the original!) and apparently it could read paper tape at 5000 characters per second. I think that might have been the program itself, on an endless loop. But the one I was thinking of belonged to a teletype, which, even if the read data was not printed but read into the host, was limited to 10cps. However if it could read and write at the same time, then it would only have taken 80 minutes or so for 50KB. -- Bartc
[toc] | [prev] | [next] | [standalone]
| From | Dr Nick <3-nospam@temporary-address.org.uk> |
|---|---|
| Date | 2011-12-16 07:05 +0000 |
| Message-ID | <87vcphm1xz.fsf@temporary-address.org.uk> |
| In reply to | #13549 |
"BartC" <bc@freeuk.com> writes: > "Ian Collins" <ian-news@hotmail.com> wrote in message > news:9ijan5Fi5oU19@mid.individual.net... >> On 11/17/11 03:32 PM, Eric Sosman wrote: >>> On 11/16/2011 9:26 AM, BartC wrote: >>>> "pozz"<pozzugno@gmail.com> wrote in message >>>> news:f06508a1-a424-4bc7-99f6-98e94e6944e6@w7g2000yqc.googlegroups.com... >>>>> On 16 Nov, 03:48, Eric Sosman<esos...@ieee-dot-org.invalid> wrote: >>>>>> [...] >>>>>> Fifty K shouldn't take long. Even on a system from forty years >>>>>> ago it didn't take long. Even on paper tape, for goodness' sake, it >>>>>> took less than a minute! >>>> >>>> (That's a fast paper tape reader. The last one I used would have taken >>>> nearly 3 hours.) >>> >>> http://www.springerlink.com/content/x42n45gk4811lpq1/ from 1963 >>> describes a "high speed paper tape reader with a maximum speed of >>> 1000 characters per second." 50KB / (1000 B/s) = 50s< one minute. >> >> That modern? The machine that preceded Colossus at Bletchley Park >> in the early 40s could read paper tape at 1000 characters per >> second! > > I've seen Colossus itself in action (the replica, not the original!) > and apparently it could read paper tape at 5000 characters per second. > > I think that might have been the program itself, on an endless loop. That loop is the message that is being attacked. The machine runs the message through, does some operations on it and carries out a set of counts on the results. If the answer is "interesting" it outputs the fact, otherwise it advances its internal state and repeats. The internal state is on uniselctors - electromechanically - and so you get a "clunk" once per tape loop as it advances. The counters are valve for speed. -- Online waterways route planner | http://canalplan.eu Plan trips, see photos, check facilities | http://canalplan.org.uk
[toc] | [prev] | [next] | [standalone]
| From | Robert Wessel <robertwessel2@yahoo.com> |
|---|---|
| Date | 2011-11-16 22:46 -0600 |
| Message-ID | <cq39c7dfa3t1sbchomjrd5ui8ru0u18lqk@4ax.com> |
| In reply to | #13535 |
On Wed, 16 Nov 2011 21:32:27 -0500, Eric Sosman <esosman@ieee-dot-org.invalid> wrote: >On 11/16/2011 9:26 AM, BartC wrote: >> "pozz" <pozzugno@gmail.com> wrote in message >> news:f06508a1-a424-4bc7-99f6-98e94e6944e6@w7g2000yqc.googlegroups.com... >>> On 16 Nov, 03:48, Eric Sosman <esos...@ieee-dot-org.invalid> wrote: >>>>[...] >>>> Fifty K shouldn't take long. Even on a system from forty years >>>> ago it didn't take long. Even on paper tape, for goodness' sake, it >>>> took less than a minute! >> >> (That's a fast paper tape reader. The last one I used would have taken >> nearly 3 hours.) > > http://www.springerlink.com/content/x42n45gk4811lpq1/ from 1963 >describes a "high speed paper tape reader with a maximum speed of >1000 characters per second." 50KB / (1000 B/s) = 50s < one minute. > > However, I realize I've erred, and in two ways. First, I've >neglected the time to punch the paper tape, an operation a good >deal slower than reading it. Second, I've overlooked an O(1) >solution: Take the original file, on paper tape, and apply a pair >of scissors to remove the first N lines -- no copying involved, >although there might be some difficulty finding enough "leader" >to feed into the read mechanism next time the data is wanted ... That's a non-issue. We repaired paper tape semi-regularly - there was special tape (with all the holes punched), and an alignment tool for aligning two pieces of paper tape, cutting them, and applying the splicing tape. In a repair, you'd repunch a section that fully overlapped the damaged area, and then splice that on to the sections to either side. If you've ever seen a (motion picture) film splicing rig, it's basically the same idea. The high speed reader/punches were, however, a lot less common than slow ones. Perhaps the single most popular reader/punch was the optional one on ASR-33s. 10cps either reading or writing (although it could do both at the same time). The fast readers were capable of eating a few yards of tape before being halted by a jam. More commonly, the sprocket/drive holes would get torn out (which you could repair with the special tape, but without actually splicing in new tape).
[toc] | [prev] | [next] | [standalone]
Page 1 of 2 [1] 2 Next page →
Back to top | Article view | comp.lang.c
csiph-web