[rust-dev] Misc questions and ideas

Patrick Walton pwalton at mozilla.com
Sun Dec 23 15:08:31 PST 2012


On 12/23/12 5:53 PM, Michael Neumann wrote:
> That's strange. If I use result::unwrap() it is consistently becoming
> much slower! But the warning goes away. While get() is faster, but
> there is this warning. Btw, there is also no .unwrap(), just
> result::unwrap(). I believe that unwrap() is copying, while get() is
> passing a reference somehow.

This is not what I see. This program:

     fn f() -> Result<~str,~str> {
         Ok(~"hello world")
     }

     fn main() {
         for uint::range(0, 0x1234567) |_| {
             let _ = f().get();
         }
     }

Has this performance:

     real	0m15.991s
     user	0m15.899s
     sys	0m0.016s

While this program:

     fn f() -> Result<~str,~str> {
         Ok(~"hello world")
     }

     fn main() {
         for uint::range(0, 0x1234567) |_| {
             let _ = result::unwrap(f());
         }
     }

Has this performance:

     real	0m4.318s
     user	0m4.255s
     sys	0m0.013s

Patrick



More information about the Rust-dev mailing list