]> git.lizzy.rs Git - rust.git/commit
Optimize String::push_byte()
authorSimon Sapin <simon.sapin@exyr.org>
Sun, 6 Jul 2014 00:11:13 +0000 (01:11 +0100)
committerSimon Sapin <simon.sapin@exyr.org>
Sun, 6 Jul 2014 00:11:13 +0000 (01:11 +0100)
commited3eee2e2a706d568f090f5d9862f0888dbdf670
treeee43e26aa4a97afec40206e6a49d2e70b19a69f4
parentb8ef5cf1310a7b1e31d0993885d867a6804597ad
Optimize String::push_byte()

```
test new_push_byte ... bench:      6985 ns/iter (+/- 487) = 17 MB/s
test old_push_byte ... bench:     19335 ns/iter (+/- 1368) = 6 MB/s
```

```rust
extern crate test;
use test::Bencher;

static TEXT: &'static str = "\
    Unicode est un standard informatique qui permet des échanges \
    de textes dans différentes langues, à un niveau mondial.";

#[bench]
fn old_push_byte(bencher: &mut Bencher) {
    bencher.bytes = TEXT.len() as u64;
    bencher.iter(|| {
        let mut new = String::new();
        for b in TEXT.bytes() {
            unsafe { new.as_mut_vec().push_all([b]) }
        }
    })
}

#[bench]
fn new_push_byte(bencher: &mut Bencher) {
    bencher.bytes = TEXT.len() as u64;
    bencher.iter(|| {
        let mut new = String::new();
        for b in TEXT.bytes() {
            unsafe { new.as_mut_vec().push(b) }
        }
    })
}
```
src/libcollections/string.rs