build(rust): vendor rnix parser crate
This commit was merged in pull request #57.
This commit is contained in:
69
third_party/crates/countme-3.0.1/examples/bench.rs
vendored
Normal file
69
third_party/crates/countme-3.0.1/examples/bench.rs
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
use std::thread;
|
||||
|
||||
use countme::{get, Count};
|
||||
|
||||
#[derive(Default)]
|
||||
struct Foo {
|
||||
_c: Count<Self>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct Bar {
|
||||
_c: Count<Self>,
|
||||
_x: i32,
|
||||
}
|
||||
|
||||
mod deeply {
|
||||
pub(crate) mod nested {
|
||||
pub(crate) mod module {
|
||||
use countme::Count;
|
||||
|
||||
#[derive(Default)]
|
||||
pub(crate) struct Quux {
|
||||
_c: Count<Self>,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
countme::enable(true);
|
||||
let t = std::time::Instant::now();
|
||||
let n = 5;
|
||||
let m = 1_000_000;
|
||||
|
||||
let mut threads = Vec::new();
|
||||
for _ in 0..n {
|
||||
threads.push(thread::spawn(move || {
|
||||
for _ in 0..m {
|
||||
Foo::default();
|
||||
}
|
||||
}));
|
||||
threads.push(thread::spawn(move || {
|
||||
let mut xs = Vec::with_capacity(m);
|
||||
for _ in 0..m {
|
||||
xs.push(Bar::default())
|
||||
}
|
||||
}));
|
||||
threads.push(thread::spawn(move || {
|
||||
for _ in 0..m {
|
||||
deeply::nested::module::Quux::default();
|
||||
}
|
||||
}));
|
||||
}
|
||||
for t in threads {
|
||||
t.join().unwrap();
|
||||
}
|
||||
|
||||
let foo = get::<Foo>();
|
||||
assert_eq!(foo.total, m * n);
|
||||
assert!(foo.max_live >= 1);
|
||||
assert_eq!(foo.live, 0);
|
||||
|
||||
let bar = get::<Bar>();
|
||||
assert_eq!(bar.total, m * n);
|
||||
assert!(bar.max_live >= m);
|
||||
assert_eq!(bar.live, 0);
|
||||
|
||||
println!("{:?}", t.elapsed());
|
||||
}
|
||||
77
third_party/crates/countme-3.0.1/examples/bench_single_thread.rs
vendored
Normal file
77
third_party/crates/countme-3.0.1/examples/bench_single_thread.rs
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
use countme::{get, Count};
|
||||
|
||||
#[derive(Default)]
|
||||
struct Foo {
|
||||
_c: Count<Self>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct Bar {
|
||||
_c: Count<Self>,
|
||||
_x: i32,
|
||||
}
|
||||
|
||||
mod deeply {
|
||||
pub(crate) mod nested {
|
||||
pub(crate) mod module {
|
||||
use countme::Count;
|
||||
|
||||
#[derive(Default)]
|
||||
pub(crate) struct Quux {
|
||||
_c: Count<Self>,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
countme::enable(true);
|
||||
let t = std::time::Instant::now();
|
||||
let n = 6;
|
||||
let m = 2_000_000;
|
||||
|
||||
for _ in 0..n {
|
||||
for _ in 0..m {
|
||||
Foo::default();
|
||||
}
|
||||
|
||||
let mut xs = Vec::with_capacity(m);
|
||||
for _ in 0..m {
|
||||
xs.push(Bar::default())
|
||||
}
|
||||
|
||||
for _ in 0..m {
|
||||
deeply::nested::module::Quux::default();
|
||||
}
|
||||
|
||||
let fs = [
|
||||
|| drop(Foo::default()),
|
||||
|| drop(Bar::default()),
|
||||
|| drop(deeply::nested::module::Quux::default()),
|
||||
|| {
|
||||
#[derive(Default)]
|
||||
struct Local(Count<Self>);
|
||||
|
||||
Local::default();
|
||||
},
|
||||
];
|
||||
for i in 0..m {
|
||||
fs[i % 4]();
|
||||
}
|
||||
}
|
||||
|
||||
let foo = get::<Foo>();
|
||||
assert_eq!(foo.total, m * n + (m * n / 4));
|
||||
assert_eq!(foo.max_live, 1);
|
||||
assert_eq!(foo.live, 0);
|
||||
|
||||
let bar = get::<Bar>();
|
||||
assert_eq!(bar.total, m * n + (m * n / 4));
|
||||
|
||||
// FIXME: why +1? This seems like a bug
|
||||
// overreporting by 1 is not significant, but anyway
|
||||
assert_eq!(bar.max_live, m + 1);
|
||||
assert_eq!(bar.live, 0);
|
||||
|
||||
println!("{:?}", t.elapsed());
|
||||
}
|
||||
11
third_party/crates/countme-3.0.1/examples/print_at_exit.rs
vendored
Normal file
11
third_party/crates/countme-3.0.1/examples/print_at_exit.rs
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
#[derive(Default)]
|
||||
struct Widget {
|
||||
_t: countme::Count<Self>,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let w1 = Widget::default();
|
||||
let _w2 = Widget::default();
|
||||
drop(w1);
|
||||
let _w3 = Widget::default();
|
||||
}
|
||||
Reference in New Issue
Block a user