Skip to content
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

Performance benchmarks #3

Closed
gsingh93 opened this issue May 5, 2015 · 5 comments
Closed

Performance benchmarks #3

gsingh93 opened this issue May 5, 2015 · 5 comments

Comments

@gsingh93
Copy link

@gsingh93 gsingh93 commented May 5, 2015

Do you have performance benchmarks showing if a SmallVec is actually faster than a normal vec? The benchmarks I came up with are showing that Vec is actually faster, or at least comparable.

#[bench]
fn bench_normal(b: &mut Bencher) {
    b.iter(|| {
        for _ in 0..10000 {
            let mut v = Vec::with_capacity(32);
            for _ in 0..32 {
                v.push(1)
            }
        }
    });
}

#[bench]
fn bench_smallvec(b: &mut Bencher) {
    b.iter(|| {
        for _ in 0..10000 {
            let mut v = SmallVec32::new();
            for _ in 0..32 {
                v.push(1)
            }
        }
    });
}

test bench_normal   ... bench:    421725 ns/iter (+/- 17460)
test bench_smallvec ... bench:    448904 ns/iter (+/- 18151)
#[bench]
fn bench_normal(b: &mut Bencher) {
    b.iter(|| {
        for _ in 0..10000 {
            let mut v = Vec::with_capacity(32);
            for _ in 0..33 {
                v.push(1)
            }
        }
    });
}

#[bench]
fn bench_smallvec(b: &mut Bencher) {
    b.iter(|| {
        for _ in 0..10000 {
            let mut v = SmallVec32::new();
            for _ in 0..33 {
                v.push(1)
            }
        }
    });
}

test bench_normal   ... bench:    749297 ns/iter (+/- 24251)
test bench_smallvec ... bench:   1295246 ns/iter (+/- 112177)
@SimonSapin
Copy link
Member

@SimonSapin SimonSapin commented May 5, 2015

@mbrubeck
Copy link
Contributor

@mbrubeck mbrubeck commented May 5, 2015

When I make the benchmark read back from the vector, a non-spilled SmallVec is faster than a Vec. Also, none of these really test memory locality and pointer indirection costs. Bigger differences should occur when a SmallVec is used as a field type in a larger structure or array.

#[bench]
fn bench_normal(b: &mut Bencher) {
    b.iter(|| {
        for _ in 0..10000 {
            let mut v = Vec::with_capacity(32);
            for _ in 0..32 {
                v.push(1)
            }
            let mut sum = 0;
            for x in v {
                sum += x;
            }
            test::black_box(sum);
        }
    });
}

#[bench]
fn bench_smallvec(b: &mut Bencher) {
    b.iter(|| {
        for _ in 0..10000 {
            let mut v = SmallVec32::new();
            for _ in 0..32 {
                v.push(1)
            }
            let mut sum = 0;
            for x in v.into_iter() {
                sum += x;
            }
            test::black_box(sum);
        }
    });
}
test bench_normal   ... bench:    704570 ns/iter (+/- 44905)
test bench_smallvec ... bench:    627145 ns/iter (+/- 31909)
@gsingh93
Copy link
Author

@gsingh93 gsingh93 commented May 5, 2015

Thanks for the explanation. It would be nice to have these and the field access benchmarks in the project itself, so it would be easier for people to evaluate whether this is something they need.

@chpio
Copy link
Contributor

@chpio chpio commented May 21, 2017

It would be nice to have these and the field access benchmarks in the project itself, so it would be easier for people to evaluate whether this is something they need.

nah, you should bench your use case

@jdm
Copy link
Member

@jdm jdm commented May 21, 2017

Benchmarks now exist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.