Skip to content

Call write_fmt directly to format an Arguments value. #24519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 18, 2015

Conversation

rprichard
Copy link
Contributor

It's just as convenient, but it's much faster. Using write! requires an
extra call to fmt::write and a extra dynamically dispatched call to
Arguments' Display format function.

It's just as convenient, but it's much faster. Using write! requires an
extra call to fmt::write and a extra dynamically dispatched call to
Arguments' Display format function.
@rust-highfive
Copy link
Contributor

r? @brson

(rust_highfive has picked a reviewer for you, use r? to override)

@rprichard
Copy link
Contributor Author

r? @alexcrichton

I benchmarked format!("Hello World") and saw a reduction from 77 ns/iter to 54 ns/iter:

// ORIGINAL CODE:
// test simple_format ... bench:        77 ns/iter (+/- 2)

// MODIFIED CODE:
// test simple_format ... bench:        54 ns/iter (+/- 6)

#![feature(test)]
extern crate test;

#[bench]
fn simple_format(b: &mut test::Bencher) {
    b.iter(|| {
        test::black_box(format!("Hello World"));
    });
}

@rust-highfive rust-highfive assigned alexcrichton and unassigned brson Apr 17, 2015
@alexcrichton
Copy link
Member

@bors: r+ 317eac3

Nice wins!

bors added a commit that referenced this pull request Apr 18, 2015
It's just as convenient, but it's much faster. Using write! requires an
extra call to fmt::write and a extra dynamically dispatched call to
Arguments' Display format function.
@bors
Copy link
Collaborator

bors commented Apr 18, 2015

⌛ Testing commit 317eac3 with merge fcf637b...

@bors bors merged commit 317eac3 into rust-lang:master Apr 18, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants