Seregon/zftpd

Zero-copy FTP/HTTP Daemon compatible with all POSIX systems

C/11.0 KB/No license
ffi/rust/benches/bench.rs
zftpd / ffi / rust / benches / bench.rs
1use std::time::Instant;
2use zftpd::{FtpServer, PalAlloc};
3 
4fn benchmark_allocator(iterations: usize) {
5 PalAlloc::init_default().unwrap();
6 let start = Instant::now();
7 
8 for _ in 0..iterations {
9 let ptr = PalAlloc::malloc(64);
10 PalAlloc::free(ptr);
11 }
12 
13 let duration = start.elapsed();
14 println!(
15 "[Rust] Allocator ({} iters): {:.2} ms",
16 iterations,
17 duration.as_secs_f64() * 1000.0
18 );
19}
20 
21fn benchmark_ftp_startup(iterations: usize) {
22 let start = Instant::now();
23 
24 for i in 0..iterations {
25 let port = 20000 + (i as u16 % 10000);
26 if let Ok(server) = FtpServer::new("127.0.0.1", port, "/tmp") {
27 if server.start().is_ok() {
28 server.stop();
29 }
30 }
31 }
32 
33 let duration = start.elapsed();
34 println!(
35 "[Rust] FtpServer start/stop ({} iters): {:.2} ms",
36 iterations,
37 duration.as_secs_f64() * 1000.0
38 );
39}
40 
41fn main() {
42 println!("--- Rust FFI Benchmarks ---");
43 benchmark_allocator(100_000);
44 benchmark_ftp_startup(1000);
45}
46