Zero-copy FTP/HTTP Daemon compatible with all POSIX systems
| 1 | import time |
| 2 | from zftpd.core import PalAlloc, FtpServer |
| 3 | |
| 4 | def benchmark_allocator(iterations=100_000): |
| 5 | PalAlloc.init_default() |
| 6 | start = time.perf_counter() |
| 7 | |
| 8 | for _ in range(iterations): |
| 9 | ptr = PalAlloc.malloc(64) |
| 10 | PalAlloc.free(ptr) |
| 11 | |
| 12 | end = time.perf_counter() |
| 13 | print(f"[Python] Allocator ({iterations} iters): {(end - start) * 1000:.2f} ms") |
| 14 | |
| 15 | |
| 16 | def benchmark_ftp_startup(iterations=1000): |
| 17 | start = time.perf_counter() |
| 18 | |
| 19 | for i in range(iterations): |
| 20 | server = FtpServer("127.0.0.1", 20000 + (i % 10000), "/tmp") |
| 21 | server.start() |
| 22 | server.stop() |
| 23 | server.close() |
| 24 | |
| 25 | end = time.perf_counter() |
| 26 | print(f"[Python] FtpServer start/stop ({iterations} iters): {(end - start) * 1000:.2f} ms") |
| 27 | |
| 28 | |
| 29 | if __name__ == "__main__": |
| 30 | print("--- Python FFI Benchmarks ---") |
| 31 | benchmark_allocator() |
| 32 | benchmark_ftp_startup() |
| 33 |