Skip to content

Commit

Permalink
test code for system load
Browse files Browse the repository at this point in the history
  • Loading branch information
Suori892 committed Nov 20, 2023
0 parents commit 6c276c7
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
75 changes: 75 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "perfomance-checker"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rand = "0.8.5"
28 changes: 28 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use std::thread;

fn factorial(n: u64) -> u64 {
if n == 0 || n == 1 {
return 1;
}
n * factorial(n - 1)
}

fn main() {
let num_threads = 10;

let handles: Vec<_> = (0..num_threads)
.map(|_| {
thread::spawn(|| {
loop {
let num = rand::random::<u64>() % 20;
let result = factorial(num);
println!("Factorial of {}: {}", num, result);
}
})
})
.collect();

for handle in handles {
handle.join().unwrap();
}
}

0 comments on commit 6c276c7

Please sign in to comment.