### Configure Threadpool with Builder Source: https://context7.com/surrealdb/affinitypool/llms.txt Use the builder pattern for fine-grained control over threadpool configuration, including worker count, thread names, stack size, and CPU affinity. This example demonstrates setting worker threads, thread names, and stack size. ```rust use affinitypool::Builder; #[tokio::main] async fn main() { let pool = Builder::new() .worker_threads(8) // Set number of worker threads .thread_name("my-worker") // Name the worker threads .thread_stack_size(4_000_000) // Set 4MB stack size per thread .build(); // Execute CPU-intensive tasks let mut handles = Vec::new(); for i in 0..100 { handles.push(pool.spawn(move || { // Verify thread name assert_eq!(std::thread::current().name(), Some("my-worker")); // Simulate heavy computation let mut sum = 0u64; for j in 0..1_000_000 { sum = sum.wrapping_add((i * j) as u64); } sum })); } // Collect all results for handle in handles { let result = handle.await; println!("Task completed with result: {}", result); } } ``` -------------------------------- ### Initialize and Use Global Threadpool Source: https://github.com/surrealdb/affinitypool/blob/main/README.md Set up a global threadpool using Threadpool::build_global() for easy access from any part of the application via the global spawn function. ```rust use affinitypool::{Threadpool, spawn}; #[tokio::main] async fn main() { // Initialize the global threadpool let pool = Threadpool::new(4); pool.build_global().expect("Global threadpool already initialized"); // Now you can use the global spawn function from anywhere let result = spawn(|| { // This runs on the global threadpool std::thread::sleep(std::time::Duration::from_millis(100)); "completed" }).await; assert_eq!(result, "completed"); // Can be called from any async context without passing the pool reference process_data().await; } async fn process_data() { let result = spawn(|| { // Complex blocking operation vec![1, 2, 3, 4, 5].iter().sum::() }).await; println!("Sum: {result}"); } ``` -------------------------------- ### Run Benchmarks with Cargo Source: https://github.com/surrealdb/affinitypool/blob/main/BENCHMARKS.md Execute benchmarks directly using the Cargo build tool. This provides more control and access to Cargo's features for running benchmarks. ```bash cargo bench --bench threadpool ``` -------------------------------- ### Global Threadpool Source: https://context7.com/surrealdb/affinitypool/llms.txt Sets up a singleton global threadpool accessible from anywhere using the `spawn()` and `spawn_local()` free functions. Useful when you want to share a single pool across your application without passing references. ```APIDOC ## Global Threadpool ### Description Sets up a singleton global threadpool accessible from anywhere using the `spawn()` and `spawn_local()` free functions. Useful when you want to share a single pool across your application without passing references. ### Method Not applicable (initialization and usage pattern) ### Endpoint Not applicable ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust use affinitypool::{Threadpool, spawn, spawn_local}; #[tokio::main] async fn main() { // Initialize the global threadpool let pool = Threadpool::new(4); pool.build_global().expect("Global threadpool already initialized"); // Use the global spawn function from anywhere let result = spawn(|| { std::thread::sleep(std::time::Duration::from_millis(100)); "completed" }).await; assert_eq!(result, "completed"); // Can be called from any async context without passing the pool reference process_data().await; } async fn process_data() { // Global spawn - no pool reference needed let result = spawn(|| { vec![1, 2, 3, 4, 5].iter().sum::() }).await; println!("Sum: {}", result); // Global spawn_local also works let data = vec![10, 20, 30]; let doubled = spawn_local(|| { data.iter().map(|x| x * 2).collect::>() }).await; println!("Doubled: {:?}", doubled); } ``` ### Response #### Success Response (200) Not applicable (initialization and usage pattern) #### Response Example None ``` -------------------------------- ### Run All Benchmarks Source: https://github.com/surrealdb/affinitypool/blob/main/BENCHMARKS.md Execute the entire benchmark suite. This command runs all defined benchmark groups to provide a comprehensive performance overview. ```bash ./run_benchmarks.sh ``` -------------------------------- ### Global Threadpool Initialization and Usage Source: https://context7.com/surrealdb/affinitypool/llms.txt Sets up a singleton global threadpool accessible via `spawn()` and `spawn_local()`. This is useful for sharing a single pool across an application without explicit reference passing. Ensure `build_global()` is called only once. ```rust use affinitypool::{Threadpool, spawn, spawn_local}; #[tokio::main] async fn main() { // Initialize the global threadpool let pool = Threadpool::new(4); pool.build_global().expect("Global threadpool already initialized"); // Use the global spawn function from anywhere let result = spawn(|| { std::thread::sleep(std::time::Duration::from_millis(100)); "completed" }).await; assert_eq!(result, "completed"); // Can be called from any async context without passing the pool reference process_data().await; } async fn process_data() { // Global spawn - no pool reference needed let result = spawn(|| { vec![1, 2, 3, 4, 5].iter().sum::() }).await; println!("Sum: {}", result); // Global spawn_local also works let data = vec![10, 20, 30]; let doubled = spawn_local(|| { data.iter().map(|x| x * 2).collect::>() }).await; println!("Doubled: {:?}", doubled); } ``` -------------------------------- ### Create and Spawn Tasks on Threadpool Source: https://github.com/surrealdb/affinitypool/blob/main/README.md Use Threadpool::new to create a threadpool and spawn blocking tasks asynchronously. Tasks are processed in FIFO order. ```rust use affinitypool::Threadpool; #[tokio::main] async fn main() { // Create a threadpool with 4 worker threads let pool = Threadpool::new(4); // Spawn a simple task let result = pool.spawn(|| { println!("Hello from a worker thread!"); 42 }).await; assert_eq!(result, 42); } ``` -------------------------------- ### Create and Use Threadpool Source: https://context7.com/surrealdb/affinitypool/llms.txt Instantiate a new threadpool with a specified number of worker threads and spawn a simple blocking task. The worker count is clamped between 1 and 512. ```rust use affinitypool::Threadpool; #[tokio::main] async fn main() { // Create a threadpool with 4 worker threads let pool = Threadpool::new(4); // Verify thread count assert_eq!(pool.num_threads(), 4); // Spawn a simple blocking task let result = pool.spawn(|| { // This runs on a dedicated worker thread println!("Hello from a worker thread!"); 42 }).await; assert_eq!(result, 42); } ``` -------------------------------- ### Configure Threadpool with Builder Source: https://github.com/surrealdb/affinitypool/blob/main/README.md Use the Builder to customize threadpool settings like worker thread count, names, and stack sizes. This is useful for optimizing workloads. ```rust use affinitypool::Builder; #[tokio::main] async fn main() { let pool = Builder::new() .worker_threads(8) // Set number of worker threads .thread_name("my-worker") // Name the worker threads .thread_stack_size(4_000_000) // Set 4MB stack size per thread .build(); // Execute CPU-intensive tasks let mut handles = Vec::new(); for i in 0..100 { handles.push(pool.spawn(move || { // Simulate heavy computation let mut sum = 0u64; for j in 0..1_000_000 { sum = sum.wrapping_add((i * j) as u64); } sum })); } // Collect results for handle in handles { let result = handle.await; println!("Task completed with result: {result}"); } } ``` -------------------------------- ### Builder API Source: https://context7.com/surrealdb/affinitypool/llms.txt Provides a fluent API for configuring threadpool settings including worker count, thread names, stack size, and CPU affinity. ```APIDOC ## Builder ### Description Provides a fluent API for configuring threadpool settings including worker count, thread names, stack size, and CPU affinity. Use the builder pattern when you need fine-grained control over pool configuration. ### Method `Builder::new()` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust use affinitypool::Builder; #[tokio::main] async fn main() { let pool = Builder::new() .worker_threads(8) // Set number of worker threads .thread_name("my-worker") // Name the worker threads .thread_stack_size(4_000_000) // Set 4MB stack size per thread .build(); // Execute CPU-intensive tasks let mut handles = Vec::new(); for i in 0..100 { handles.push(pool.spawn(move || { // Verify thread name assert_eq!(std::thread::current().name(), Some("my-worker")); // Simulate heavy computation let mut sum = 0u64; for j in 0..1_000_000 { sum = sum.wrapping_add((i * j) as u64); } sum })); } // Collect all results for handle in handles { let result = handle.await; println!("Task completed with result: {}", result); } } ``` ### Response #### Success Response (200) - **Threadpool** - A configured `Threadpool` instance. #### Response Example None (This is a builder pattern for creating a Threadpool instance) ``` -------------------------------- ### Run Specific Benchmark Group Source: https://github.com/surrealdb/affinitypool/blob/main/BENCHMARKS.md Execute a particular benchmark group, such as 'basic_operations'. This is useful for focusing on specific performance aspects or during development. ```bash ./run_benchmarks.sh basic_operations ``` -------------------------------- ### Pin Worker Threads to CPU Cores with Builder Source: https://github.com/surrealdb/affinitypool/blob/main/README.md Configure the threadpool using Builder to pin each worker thread to a specific CPU core for enhanced performance and cache locality. ```rust use affinitypool::Builder; #[tokio::main] async fn main() { // Create a pool with one thread per CPU core, each pinned to its respective core let pool = Builder::new() .thread_per_core(true) .build(); // Tasks will be distributed across CPU cores for i in 0..100 { pool.spawn(move || { println!("Task {i} running on dedicated CPU core"); // Perform CPU-intensive work with better cache locality }).await; } } ``` -------------------------------- ### Spawn Task with Local Data Borrowing Source: https://context7.com/surrealdb/affinitypool/llms.txt Spawn a task that can borrow local data without requiring a 'static lifetime. The future will block the current thread if dropped before completion, ensuring borrowed data remains valid. Use this when you need to process local data without cloning. ```rust use affinitypool::Threadpool; #[tokio::main] async fn main() { let pool = Threadpool::new(4); // Local data that doesn't need to be 'static let data = vec![1, 2, 3, 4, 5]; let multiplier = 10; // spawn_local allows borrowing local data let result = pool.spawn_local(|| { data.iter() .map(|x| x * multiplier) .collect::>() }).await; println!("Result: {:?}", result); // [10, 20, 30, 40, 50] // Original data is still accessible after spawn_local println!("Original data: {:?}", data); // Works with complex borrowed data structures let config = ("host", 8080); let message = pool.spawn_local(|| { format!("Connecting to {}:{}", config.0, config.1) }).await; println!("{}", message); } ``` -------------------------------- ### Threadpool::new Source: https://context7.com/surrealdb/affinitypool/llms.txt Creates a new threadpool with a specified number of worker threads. The worker count is clamped between 1 and 512. ```APIDOC ## Threadpool::new ### Description Creates a new threadpool with a specified number of worker threads. This is the simplest way to instantiate a pool for running blocking tasks asynchronously. The worker count is clamped between 1 and 512 (MAX_THREADS). ### Method `Threadpool::new(num_threads: usize)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust use affinitypool::Threadpool; #[tokio::main] async fn main() { // Create a threadpool with 4 worker threads let pool = Threadpool::new(4); // Verify thread count assert_eq!(pool.num_threads(), 4); // Spawn a simple blocking task let result = pool.spawn(|| { // This runs on a dedicated worker thread println!("Hello from a worker thread!"); 42 }).await; assert_eq!(result, 42); } ``` ### Response #### Success Response (200) None (This is a constructor) #### Response Example None ``` -------------------------------- ### Error Handling for Global Threadpool Source: https://context7.com/surrealdb/affinitypool/llms.txt Handles errors when initializing a global threadpool, specifically catching `GlobalThreadpoolExists` if a second pool is attempted. ```rust use affinitypool::{Threadpool, Error}; #[tokio::main] async fn main() { // First global pool initialization succeeds let pool1 = Threadpool::new(4); let result1 = pool1.build_global(); assert!(result1.is_ok()); // Second attempt fails with GlobalThreadpoolExists error let pool2 = Threadpool::new(2); let result2 = pool2.build_global(); match result2 { Ok(_) => println!("Unexpected success"), Err(Error::GlobalThreadpoolExists) => { println!("Global threadpool already exists - expected behavior"); } } // The original global pool is still available use affinitypool::spawn; let result = spawn(|| 42).await; assert_eq!(result, 42); } ``` -------------------------------- ### Spawn Multiple Concurrent Blocking Tasks Source: https://context7.com/surrealdb/affinitypool/llms.txt Queue multiple blocking tasks for execution on the threadpool and await their completion. Tasks are processed in FIFO order. The closure must be `Send + 'static` and its return type must be `Send + 'static`. ```rust use affinitypool::Threadpool; use std::sync::{Arc, atomic::{AtomicUsize, Ordering}}; #[tokio::main] async fn main() { let pool = Threadpool::new(4); let counter = Arc::new(AtomicUsize::new(0)); // Spawn multiple concurrent blocking tasks let mut handles = Vec::new(); for i in 0..100 { let counter = counter.clone(); handles.push(pool.spawn(move || { // Simulate blocking I/O or computation std::thread::sleep(std::time::Duration::from_millis(10)); counter.fetch_add(1, Ordering::SeqCst); format!("Task {} completed", i) })); } // Await all tasks to complete for handle in handles { let result = handle.await; println!("{}", result); } assert_eq!(counter.load(Ordering::SeqCst), 100); } ``` -------------------------------- ### Builder::thread_per_core Source: https://context7.com/surrealdb/affinitypool/llms.txt Configures a thread pool to spawn one worker thread per CPU core, pinning each thread to its respective core. This is beneficial for CPU-bound workloads to improve cache locality and reduce context switching. ```rust use affinitypool::Builder; #[tokio::main] async fn main() { // Create a pool with one thread per CPU core, each pinned to its core let pool = Builder::new() .thread_per_core(true) .build(); println!("Pool has {} threads (one per CPU core)", pool.num_threads()); // Tasks are distributed across CPU cores with affinity let mut handles = Vec::new(); for i in 0..100 { handles.push(pool.spawn(move || { // This runs on a thread pinned to a specific CPU core // CPU-intensive work benefits from better cache locality let mut result = 0u64; for j in 0..10_000_000 { result = result.wrapping_add(i as u64 * j); } result })); } for handle in handles { let _ = handle.await; } } ``` -------------------------------- ### Threadpool::spawn_local Source: https://context7.com/surrealdb/affinitypool/llms.txt Spawns a task that can borrow local data without requiring 'static lifetime. The future will block the current thread if dropped before completion. ```APIDOC ## Threadpool::spawn_local ### Description Spawns a task that can borrow local data without requiring `'static` lifetime. The future will block the current thread if dropped before completion, ensuring borrowed data remains valid. Use this when you need to process local data without cloning. ### Method `pool.spawn_local(f: F) -> JoinHandle` where `F: FnOnce() -> R + Send + 'static`, `R: Send + 'static` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust use affinitypool::Threadpool; #[tokio::main] async fn main() { let pool = Threadpool::new(4); // Local data that doesn't need to be 'static let data = vec![1, 2, 3, 4, 5]; let multiplier = 10; // spawn_local allows borrowing local data let result = pool.spawn_local(|| { data.iter() .map(|x| x * multiplier) .collect::>() }).await; println!("Result: {:?}", result); // [10, 20, 30, 40, 50] // Original data is still accessible after spawn_local println!("Original data: {:?}", data); // Works with complex borrowed data structures let config = ("host", 8080); let message = pool.spawn_local(|| { format!("Connecting to {}:{}", config.0, config.1) }).await; println!("{}", message); } ``` ### Response #### Success Response (200) - **result** (R) - The result returned by the spawned closure. #### Response Example ```json { "result": [10, 20, 30, 40, 50] } ``` ``` -------------------------------- ### Pin Thread to CPU Core Source: https://context7.com/surrealdb/affinitypool/llms.txt Pins the current thread to a specific CPU core. Returns true if successful, false otherwise. Useful for manual thread affinity control. ```rust use affinitypool::affinity::{self, CoreId}; fn main() { // Create a CoreId from a usize let core_id: CoreId = 0.into(); // Pin the current thread to core 0 if affinity::set_for_current(core_id) { println!("Successfully pinned to core 0"); // This thread now has affinity to core 0 // CPU-intensive work will benefit from cache locality let result: u64 = (0..10_000_000u64).sum(); println!("Computation result: {}", result); } else { println!("Failed to set CPU affinity"); } // Common pattern: distribute work across cores if let Some(cores) = affinity::get_core_ids() { let handles: Vec<_> = cores.iter().enumerate().map(|(i, &core_id)| { std::thread::spawn(move || { affinity::set_for_current(core_id); // Each thread processes its portion of work on a dedicated core let chunk_size = 1_000_000; let start = i * chunk_size; let end = start + chunk_size; (start..end).map(|x| x as u64).sum::() }) }).collect(); let total: u64 = handles.into_iter().map(|h| h.join().unwrap()).sum(); println!("Total: {}", total); } } ``` -------------------------------- ### affinity::get_core_ids Source: https://context7.com/surrealdb/affinitypool/llms.txt Retrieves information on all CPU cores available to the current thread. Returns a vector of `CoreId` values that can be used with `set_for_current()` to pin threads to specific cores. Supports Linux, macOS, Windows, FreeBSD, and Android. ```APIDOC ## affinity::get_core_ids ### Description Retrieves information on all CPU cores available to the current thread. Returns a vector of `CoreId` values that can be used with `set_for_current()` to pin threads to specific cores. Supports Linux, macOS, Windows, FreeBSD, and Android. ### Method Not applicable (utility function) ### Endpoint Not applicable ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust use affinitypool::affinity; fn main() { // Get all available CPU core IDs if let Some(core_ids) = affinity::get_core_ids() { println!("Available CPU cores: {}", core_ids.len()); for core_id in &core_ids { println!("Core ID: {}", core_id.id); } // Create threads pinned to specific cores let handles: Vec<_> = core_ids.into_iter().map(|id| { std::thread::spawn(move || { // Pin this thread to the specified core let success = affinity::set_for_current(id); if success { println!("Thread pinned to core {}", id.id); // Perform CPU-intensive work with better cache locality let mut sum = 0u64; for i in 0..10_000_000 { sum = sum.wrapping_add(i); } sum } else { println!("Failed to pin thread to core {}", id.id); 0 } }) }).collect(); for handle in handles { let result = handle.join().unwrap(); println!("Result: {}", result); } } else { println!("CPU affinity not supported on this platform"); } } ``` ### Response #### Success Response (200) - **core_ids** (Vec) - A vector of `CoreId` representing available CPU cores. #### Response Example ```json { "core_ids": [ {"id": 0}, {"id": 1}, // ... more core IDs ] } ``` ``` -------------------------------- ### Builder::thread_per_core Source: https://context7.com/surrealdb/affinitypool/llms.txt Enables CPU affinity mode where one worker thread is spawned per CPU core, with each thread pinned to its respective core. This improves cache locality and reduces context switching for CPU-bound workloads. ```APIDOC ## Builder::thread_per_core ### Description Enables CPU affinity mode where one worker thread is spawned per CPU core, with each thread pinned to its respective core. This improves cache locality and reduces context switching for CPU-bound workloads. ### Method Not applicable (configuration option for Builder) ### Endpoint Not applicable ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust use affinitypool::Builder; #[tokio::main] async fn main() { // Create a pool with one thread per CPU core, each pinned to its core let pool = Builder::new() .thread_per_core(true) .build(); println!("Pool has {} threads (one per CPU core)", pool.num_threads()); // Tasks are distributed across CPU cores with affinity let mut handles = Vec::new(); for i in 0..100 { handles.push(pool.spawn(move || { // This runs on a thread pinned to a specific CPU core // CPU-intensive work benefits from better cache locality let mut result = 0u64; for j in 0..10_000_000 { result = result.wrapping_add(i as u64 * j); } result })); } for handle in handles { let _ = handle.await; } } ``` ### Response #### Success Response (200) Not applicable (configuration method) #### Response Example None ``` -------------------------------- ### Spawn Local Tasks with Borrowed Data Source: https://github.com/surrealdb/affinitypool/blob/main/README.md Use spawn_local on a Threadpool to execute tasks that borrow data from the current scope, avoiding the 'static lifetime requirement. ```rust use affinitypool::Threadpool; #[tokio::main] async fn main() { let pool = Threadpool::new(4); let data = vec![1, 2, 3, 4, 5]; let multiplier = 10; // spawn_local allows borrowing local data let result = pool.spawn_local(|| { data.iter() .map(|x| x * multiplier) .collect::>() }).await; println!("Result: {result:?}"); // [10, 20, 30, 40, 50] // data is still accessible after spawn_local println!("Original data: {data:?}"); } ``` -------------------------------- ### Handle Multiple Concurrent Blocking Tasks Source: https://github.com/surrealdb/affinitypool/blob/main/README.md Spawn numerous blocking tasks concurrently using a Threadpool and collect their results. This is suitable for I/O-bound or CPU-bound operations that can be parallelized. ```rust use affinitypool::Threadpool; use std::sync::{Arc, atomic::{AtomicUsize, Ordering}}; #[tokio::main] async fn main() { let pool = Threadpool::new(4); let counter = Arc::new(AtomicUsize::new(0)); // Spawn multiple tasks concurrently let mut handles = Vec::new(); for i in 0..100 { let counter = counter.clone(); handles.push(pool.spawn(move || { // Simulate blocking I/O or computation std::thread::sleep(std::time::Duration::from_millis(10)); counter.fetch_add(1, Ordering::SeqCst); format!("Task {i} completed") })); } // Wait for all tasks to complete for handle in handles { let result = handle.await; println!("{result}"); } assert_eq!(counter.load(Ordering::SeqCst), 100); println!("All tasks completed!"); } ``` -------------------------------- ### affinity::get_core_ids Source: https://context7.com/surrealdb/affinitypool/llms.txt Retrieves `CoreId` values for all available CPU cores. These IDs can be used with `affinity::set_for_current()` to pin threads to specific cores, enhancing performance for CPU-intensive tasks by improving cache locality. Supports multiple platforms. ```rust use affinitypool::affinity; fn main() { // Get all available CPU core IDs if let Some(core_ids) = affinity::get_core_ids() { println!("Available CPU cores: {}", core_ids.len()); for core_id in &core_ids { println!("Core ID: {}", core_id.id); } // Create threads pinned to specific cores let handles: Vec<_> = core_ids.into_iter().map(|id| { std::thread::spawn(move || { // Pin this thread to the specified core let success = affinity::set_for_current(id); if success { println!("Thread pinned to core {}", id.id); // Perform CPU-intensive work with better cache locality let mut sum = 0u64; for i in 0..10_000_000 { sum = sum.wrapping_add(i); } sum } else { println!("Failed to pin thread to core {}", id.id); 0 } }) }).collect(); for handle in handles { let result = handle.join().unwrap(); println!("Result: {}", result); } } else { println!("CPU affinity not supported on this platform"); } } ``` -------------------------------- ### Threadpool::spawn Source: https://context7.com/surrealdb/affinitypool/llms.txt Queues a blocking task for execution on the threadpool and returns a future that resolves to the task's result. Tasks are processed in FIFO order. ```APIDOC ## Threadpool::spawn ### Description Queues a blocking task for execution on the threadpool and returns a future that resolves to the task's result. The closure must be `Send + 'static` and its return type must be `Send + 'static`. Tasks are processed in FIFO order by available worker threads. ### Method `pool.spawn(f: F) -> JoinHandle` where `F: FnOnce() -> R + Send + 'static`, `R: Send + 'static` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust use affinitypool::Threadpool; use std::sync::{Arc, atomic::{AtomicUsize, Ordering}}; #[tokio::main] async fn main() { let pool = Threadpool::new(4); let counter = Arc::new(AtomicUsize::new(0)); // Spawn multiple concurrent blocking tasks let mut handles = Vec::new(); for i in 0..100 { let counter = counter.clone(); handles.push(pool.spawn(move || { // Simulate blocking I/O or computation std::thread::sleep(std::time::Duration::from_millis(10)); counter.fetch_add(1, Ordering::SeqCst); format!("Task {} completed", i) })); } // Await all tasks to complete for handle in handles { let result = handle.await; println!("{}", result); } assert_eq!(counter.load(Ordering::SeqCst), 100); } ``` ### Response #### Success Response (200) - **result** (R) - The result returned by the spawned closure. #### Response Example ```json { "result": "Task 5 completed" } ``` ``` -------------------------------- ### CPU Intensive Task Workload Source: https://github.com/surrealdb/affinitypool/blob/main/BENCHMARKS.md A Rust function simulating a CPU-bound task by performing arithmetic operations. The iteration count can be adjusted to vary workload intensity. ```rust fn cpu_task(iterations: usize) -> usize { let mut sum: usize = 0; for i in 0..iterations { sum = sum.wrapping_add(i * 17 + 42); } sum } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.