Skip to content

Instantly share code, notes, and snippets.

@afeistel
Last active January 1, 2024 21:35
Show Gist options
  • Select an option

  • Save afeistel/469ade1095106d7132cd0fbc9bdbe8af to your computer and use it in GitHub Desktop.

Select an option

Save afeistel/469ade1095106d7132cd0fbc9bdbe8af to your computer and use it in GitHub Desktop.
I used this to debug ruchei's performance
use std::{
sync::atomic::{AtomicBool, Ordering},
thread,
time::Duration,
};
static SAMPLE: AtomicBool = AtomicBool::new(false);
fn set_sample(sample: bool) {
SAMPLE.store(sample, Ordering::Release)
}
fn sample() -> bool {
SAMPLE.load(Ordering::Acquire)
}
fn sample_thread() {
let mut counts = Vec::new();
loop {
for _ in 0..10 {
let mut count = 0;
for _ in 0..1000 {
if sample() {
count += 1;
}
thread::sleep(Duration::from_micros(100));
}
counts.push(count);
}
eprintln!("sample: {counts:?}");
counts.clear();
}
}
pub fn start_sample() {
thread::spawn(sample_thread);
}
@afeistel
Copy link
Copy Markdown
Author

afeistel commented Jan 1, 2024

the issue, in the end, was to do with .incoming() in async-tungstenite

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment