解析文件.. [英] parsing a file..

查看:57
本文介绍了解析文件..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要解析一个大约有2000行的文件而且我得到了

告诉他们在ascii中读取文件会比较简单。

所以我需要通过大块读取它来求助于二进制文件。可以任何

一个请解释一下这是什么

这个怎么样?

I need to parse a file which has about 2000 lines and I''m getting
told that reading the file in ascii would be a slower way to do it and
so i need to resort to binary by reading it in large chunks. Can any
one please explain what is all
this about ?

推荐答案

broli说:
broli said:

我需要解析一个大约有2000行的文件而且我得到了

告诉我在ascii中读取文件会做一个较慢的方法和

所以我需要通过大块读取它来求助于二进制文件。任何

一个请解释一下这是什么意思?
I need to parse a file which has about 2000 lines and I''m getting
told that reading the file in ascii would be a slower way to do it and
so i need to resort to binary by reading it in large chunks. Can any
one please explain what is all this about ?



有人在拉你的腿。 2000行文字什么都没有。只需编写

程序,使其清晰,正确且易于理解。然后,如果和

只是在它太慢的时候(你应该在开始写作之前定义足够快&/太慢

边界该程序),现在是时候考虑

如何更快地制作它。


-

理查德Heathfield< http://www.cpax.org.uk>

电子邮件:-http:// www。 + rjh @

谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>

Usenet是一个奇怪的放置" - dmr 1999年7月29日

Someone''s pulling your leg. 2000 lines of text is nothing. Just write the
program so that it''s clear, correct, and easy to understand. Then, if and
only if it''s too slow (and you should define the "fast enough"/"too slow"
boundary before you start writing the program), it''s time to think about
how it might be made faster.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999


broli说:


< snip>
broli said:

<snip>

但是后来我告诉他们b $ b通常我们不会在ascii中读取科学数据,因为

准确性和速度问题这让我想知道什么是错的?
But then I
was told that " normally we don''t read scientific data in ascii for
accuracy and speed concerns" which made me wonder what was so wrong ?



声明!

The statement!


我几乎可以在任何时间解析2000行并且没有问题

也有ascii。
I could parse 2000 lines in hardly any time and there was no problem
with ascii either.



对。有人在拉你的腿,或过分关注效率

,这会牺牲开发时间和清晰度。这并不是说

效率并不重要。但是,为了

参数,我们只是假装你写它/两个/方式,然后你测量。你发现那个二进制是bb。技术需要0.025秒来处理

2000个数据组,而text则需要0.025秒。版本需要0.075秒 - 三个

倍慢!当然这对二元来说是一个胜利!


是的,对,但是谁在乎呢?你按下ENTER,然后你需要0.1

秒来查看屏幕,一切都已经完成,无论你使用哪一个



写清楚,简单,正确。然后担心速度,当且仅当你需要

时。


-

Richard Heathfield< http:// www.cpax.org.uk>

电子邮件:-http:// www。 + rjh @

谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>

Usenet是一个奇怪的放置" - dmr 1999年7月29日

Right. Someone''s pulling your leg, or is overly concerned with efficiency
at the expense of development time and clarity. That isn''t to say that
efficiency isn''t important. But let''s just pretend, for the sake of
argument, that you write it /both/ ways, and then you measure. You
discover that the "binary" technique takes 0.025 seconds to process the
2000 data groups, whereas the "text" version takes 0.075 seconds - three
times slower! Surely this is a triumph for binary!

Yeah, right, but who cares? You press ENTER, and then it takes you 0.1
seconds to look up at the screen, and everything''s finished, no matter
which one you ran.

Write it clear, simple, and correct. Then worry about speed if and only if
you have to.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999


文章< 4e ************************* ********* @ s19g2000prg。 googlegroups.com>,

broli< Br ***** @ gmail.comwrote:
In article <4e**********************************@s19g2000prg. googlegroups.com>,
broli <Br*****@gmail.comwrote:

>我需要解析一个文件有大约2000行,我得到
告诉读取ascii中的文件将是一个较慢的方式来做到这一点和
所以我需要通过大块读取它来求助于二进制文件。任何
一个请解释一下这是什么意思?
>I need to parse a file which has about 2000 lines and I''m getting
told that reading the file in ascii would be a slower way to do it and
so i need to resort to binary by reading it in large chunks. Can any
one please explain what is all this about ?



读取大块与无论是二元还是

ascii无关。也许它们意味着每次使用

getchar()的字符读取速度很慢,这在某些系统上是这样。你可以在文本文件上使用fread()来完美地支付



- 理查德


-

:wq

Reading in large chunks is unrelated to whether it''s binary or
ascii. Perhaps they meant that character-at-a-time reading with
getchar() is slow, which it is on some systems. You can perfectly
well use fread() on text files.

-- Richard

--
:wq


这篇关于解析文件..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆