New week, new Rust! What are you folks up to?
Joined the Open Source OS Learning Camp launched by Tsinghua University, and finished the reading and exersices in GitHub - rcore-os/rCore-Tutorial-v3: Let's write an OS which can run on RISC-V in Rust from scratch! .
In the final period from the this week to next month, I'll learn how to write an async OS with the power of async Rust.
Building frontend for the E-commerce website I've been building. I will be using yew
for the frontend part. I've already built the backend using axum
.
Here is the project GitHub - yrncolloo/E-commerce: A fully E-commerce application built using rust
Playing around to see how fast I can insert into my BTreeMap, compared to inserting into a Vec. Vec is still faster by a factor of 2. I am not entirely sure why yet. The test is to insert 10,000 pairs of (usize,usize), and repeat this 1,000 times. Results below. So 10 million inserts altogether.
Tests:
const REP: usize = if cfg!(miri) { 2 } else { 1000 };
const N: usize = if cfg!(miri) { 100 } else { 10000 };
`#[test]
fn exp_cursor_seq_insert_only_test() {
for _rep in 0..REP {
let n = N;
let ct = DefaultAllocTuning::new(2048,10000);
let mut m = BTreeMap::with_tuning(ct);
let mut c = m.lower_bound_mut(Bound::Unbounded);
for i in 0..n {
c.insert_before_unchecked(i, i);
}
}
}
#[test]
fn std_vec_seq_insert_only_test() {
for _rep in 0..REP {
let mut vec = Vec::<(usize, usize)>::default();
let n = N;
for i in 0..n {
vec.push((i, i));
}
if _rep == 0 {
print_memory();
}
}
}`
Results:
C:\Users\ano31\Rust\pstd>cargo test --release cursor_seq
Finished `release` profile [optimized] target(s) in 0.12s
Running unittests src\lib.rs (target\release\deps\pstd-262fcdb933ae7946.exe)
running 1 test
test collections::btree_map::mytests::exp_cursor_seq_insert_only_test ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 102 filtered out; finished in 0.06s
C:\Users\ano31\Rust\pstd>cargo test --release vec
Finished `release` profile [optimized] target(s) in 0.12s
Running unittests src\lib.rs (target\release\deps\pstd-262fcdb933ae7946.exe)
running 1 test
test collections::btree_map::mytests::std_vec_seq_insert_only_test ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 102 filtered out; finished in 0.03s
( The standard BTreeMap takes 0.4 seconds for this test, about 6 times slower, mostly due to having to allocate more often. In summary times are 0.03 sec for vec, 0.06 sec for my BTreeMap with tuning, 0.18 seconds for my BTreeMap without tuning, 0.4 seconds for standard BTreeMap ).
I was wondering if it could be faster to insert into my BTreeMap than into a Vec, as a Vec has to do some copying when it doubles the allocation. In the end, it seems this is not quite the case, but it is quite interesting. Eventually I got close after increasing the map size a bit.
test collections::btree_map::mytests::exp_cursor_tuned_insert_only_test .
.. finished in 0.08s
test collections::btree_map::mytests::std_vec_seq_insert_only_test
... finished in 0.05s
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.