[rust-dev] read file line by line

Mic mictadlo at gmail.com
Sun Apr 8 16:52:58 PDT 2012


Hello,
Thank you it is working. I created a writing and reading benchmark. In both
cases Python is about 3 times faster than Rust.

Please find below the results and attached the codes (create_csv.py/rs has
to run first, because it creates a csv file which is used for csv.py/rs)

*BENCHMARK 1*: Writting 4000000 lines to a file

$ time python csv_create.py

real    0m3.620s
user    0m1.942s
sys     0m0.339s
$ ls -ahl csv.csv
-rw-r--r-- 1 mictadlo mictadlo 226M Apr  9 09:05 csv.csv


$ time ./csv_create

real    0m11.299s
user    0m3.222s
sys     0m5.973s
$ ls -ahl csv.csv
-rw-r--r-- 1 mictadlo mictadlo 226M Apr  9 09:07 csv.csv


*BENCHMARK 2: *Readind a csv file and trim each field

$ time python csv.py

real    0m22.136s
user    0m21.728s
sys     0m0.095s

$ time ./csv

real    1m6.796s
user    1m6.364s
sys     0m0.145s

If you guys happy benchmark than I could commit it to git. What is the git
command to commit in 'src/test/bench'?

Thank you in advance.

On Sun, Apr 8, 2012 at 9:13 AM, Brian Anderson <banderson at mozilla.com>wrote:

> **
> On 04/06/2012 06:48 PM, Mic wrote:
>
> Hi
> I have trouble to compile the following code:
>
>  import io::reader_util;
> import vec::map;
>
>  fn main(args: [str]) {
>
>      let r = io::file_reader(args[1]); // r is result<reader, err_str>
>     if result::failure(r) {
>         fail result::get_err(r);
>     }
>
>      let rdr = result::get(r);
>
>      while !rdr.eof() {
>         let line = rdr.read_line();
>         io::println(line);
>         if str::len(line) != 0u {
>             let parts = vec::map(line.split_char(',')) {|s|
>                 str::trim(s)
>             };
>         }
>
>      }
> }
>
>  and got the errors:
>  $ rustc csv.rs
> csv.rs:17:33: 17:48 error: attempted access of field split_char on type
> str, but no public field or method with that name was found
> csv.rs:17             let parts = vec::map(line.split_char(',')) {|s|
>
>  ^~~~~~~~~~~~~~~
> csv.rs:17:33: 17:53 error: the type of this value must be known in this
> context
> csv.rs:17             let parts = vec::map(line.split_char(',')) {|s|
>
>  ^~~~~~~~~~~~~~~~~~~~
>
>  What did I do wrong?
>
>
> Hi Mic.
>
> The available extension methods (as in `line.split_char(',')`) have been
> changing a lot recently, so my guess is that your compiler is just slightly
> out of date and doesn't have the `split_char` extension on `str`. Try
> updating to Rust HEAD where you will also notice that `result::failure` is
> now called `result::is_failure`.
>
> -Brian
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20120409/b2fe48a4/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: csv_create.rs
Type: application/octet-stream
Size: 420 bytes
Desc: not available
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20120409/b2fe48a4/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: csv_create.py
Type: application/octet-stream
Size: 205 bytes
Desc: not available
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20120409/b2fe48a4/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: csv.rs
Type: application/octet-stream
Size: 486 bytes
Desc: not available
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20120409/b2fe48a4/attachment-0002.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: csv.py
Type: application/octet-stream
Size: 255 bytes
Desc: not available
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20120409/b2fe48a4/attachment-0003.obj>


More information about the Rust-dev mailing list