Skip to content

Commit

Permalink
Use new vec! repeat functionality (rust-lang/rfcs#832) and Vec to Sli…
Browse files Browse the repository at this point in the history
…ce deref functionality (rust-lang/rfcs#241).
  • Loading branch information
daramos committed Feb 18, 2015
1 parent b414c9a commit 50e39d5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ Workaround for [Rust issue 16913](/~https://github.com/rust-lang/rust/issues/16913
```rust
#[bench]
fn slice_cmp(b: &mut test::Bencher) {
let vec1 = repeat(b'c').take(10_000).collect::<Vec<_>>();
let vec1 = vec![b'c';10_000];
let vec2 = vec1.clone();

b.bytes = vec1.len() as u64;
b.iter(|| {
let (s1, s2) = ( &*vec1, &*vec2 );
let (s1, s2) = ( &vec1, &vec2 );
return s1==s2
});
}
Expand All @@ -27,12 +27,12 @@ extern crate memcmp;
use memcmp::Memcmp;
#[bench]
fn memcmp_cmp(b: &mut test::Bencher) {
let vec1 = repeat(b'c').take(10_000).collect::<Vec<_>>();
let vec1 = vec![b'c';10_000];
let vec2 = vec1.clone();

b.bytes = vec1.len() as u64;
b.iter(|| {
let (s1, s2) = ( &*vec1, &*vec2 );
let (s1, s2) = ( &vec1, &vec2 );
return s1.memcmp(s2)
});
}
Expand Down
16 changes: 8 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ memcmp_impl!(i64,64);

#[cfg(test)]
mod tests {

use std::iter::repeat;
use ::Memcmp;
use ::test;

Expand All @@ -63,7 +61,7 @@ mod tests {
fn $fn_name() {
let val1 = vec![1 as $int_type,2 as $int_type,3 as $int_type,4 as $int_type];
let val2 = val1.clone();
assert!((&*val1).memcmp(&*val2));
assert!((&val1).memcmp(&val2));
}
);
}
Expand All @@ -75,7 +73,7 @@ mod tests {
fn $fn_name() {
let val1 = vec![1 as $int_type,2 as $int_type,3 as $int_type,4 as $int_type];
let val2 = vec![1 as $int_type,2 as $int_type,2 as $int_type,4 as $int_type];
assert!((&*val1).memcmp(&*val2));
assert!((&val1).memcmp(&val2));
}
);
}
Expand All @@ -86,12 +84,13 @@ mod tests {
#[bench]
fn $fn_name(b: &mut test::Bencher) {
let num_bytes = ($bits)/8;
let vec1 = repeat('c' as $int_type).take(10_000).collect::<Vec<_>>();
let val = 'c' as $int_type;
let vec1 = vec![val;10_000];
let vec2 = vec1.clone();

b.bytes = (vec1.len() * (num_bytes)) as u64;
b.iter(|| {
let (s1, s2) = ( &*vec1, &*vec2 );
let (s1, s2) = ( &vec1, &vec2 );
return s1==s2
});
}
Expand All @@ -104,12 +103,13 @@ mod tests {
#[bench]
fn $fn_name(b: &mut test::Bencher) {
let num_bytes = ($bits)/8;
let vec1 = repeat('c' as $int_type).take(10_000).collect::<Vec<_>>();
let val = 'c' as $int_type;
let vec1 = vec![val;10_000];
let vec2 = vec1.clone();

b.bytes = (vec1.len() * (num_bytes)) as u64;
b.iter(|| {
let (s1, s2) = ( &*vec1, &*vec2 );
let (s1, s2) = ( &vec1, &vec2 );
return s1.memcmp(s2)
});
}
Expand Down

0 comments on commit 50e39d5

Please sign in to comment.