Zero-copy FTP/HTTP Daemon compatible with all POSIX systems
| 1 | package org.zftpd.ffi; |
| 2 | |
| 3 | public class BenchJava { |
| 4 | |
| 5 | public static void benchmarkAllocator(int iterations) { |
| 6 | PalAlloc.initDefault(); |
| 7 | long start = System.nanoTime(); |
| 8 | |
| 9 | for (int i = 0; i < iterations; i++) { |
| 10 | long ptr = PalAlloc.malloc(64); |
| 11 | PalAlloc.free(ptr); |
| 12 | } |
| 13 | |
| 14 | long end = System.nanoTime(); |
| 15 | double ms = (end - start) / 1_000_000.0; |
| 16 | System.out.printf("[Java] Allocator (%d iters): %.2f ms\n", iterations, ms); |
| 17 | } |
| 18 | |
| 19 | public static void benchmarkFtpStartup(int iterations) { |
| 20 | long start = System.nanoTime(); |
| 21 | |
| 22 | for (int i = 0; i < iterations; i++) { |
| 23 | int port = 20000 + (i % 10000); |
| 24 | try (FtpServer server = new FtpServer("127.0.0.1", port, "/tmp")) { |
| 25 | if (server.start() == 0) { |
| 26 | server.stop(); |
| 27 | } |
| 28 | } catch (Exception e) { |
| 29 | // Ignore, as ports may be closing |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | long end = System.nanoTime(); |
| 34 | double ms = (end - start) / 1_000_000.0; |
| 35 | System.out.printf("[Java] FtpServer start/stop (%d iters): %.2f ms\n", iterations, ms); |
| 36 | } |
| 37 | |
| 38 | public static void main(String[] args) { |
| 39 | System.out.println("--- Java FFI Benchmarks ---"); |
| 40 | benchmarkAllocator(100_000); |
| 41 | benchmarkFtpStartup(1000); |
| 42 | } |
| 43 | } |
| 44 |