Files
zftpd/ffi/benchmarks/BenchJava.java
T
Seregon 2092cd5041 Add FFI subsystem with languages and Makefile
Introduce a multi-language FFI layer and build/test integration. Adds a C-core ABI (ffi/c_core/pal_ffi.h, pal_ffi.c) exposing allocator, event-loop, FTP and HTTP server primitives, plus language bindings and tests: Java (JNI wrapper, Java classes, tests, bench), Go (cgo wrapper + tests), Python (CFFI module + pytest tests, benchmarks), and Rust (crate, benches/tests). Add feasibility/benchmark report and helper benchmark scripts. Integrate FFI into the Makefile with new ffi targets (ffi, ffi-java, ffi-rust, ffi-python, ffi-go), shared-library build rules, object rules, and minor .gitignore updates; also includes other test files and a modification to src/http_api.c.
2026-02-27 17:36:40 +01:00

44 lines
1.4 KiB
Java

package org.zftpd.ffi;
public class BenchJava {
public static void benchmarkAllocator(int iterations) {
PalAlloc.initDefault();
long start = System.nanoTime();
for (int i = 0; i < iterations; i++) {
long ptr = PalAlloc.malloc(64);
PalAlloc.free(ptr);
}
long end = System.nanoTime();
double ms = (end - start) / 1_000_000.0;
System.out.printf("[Java] Allocator (%d iters): %.2f ms\n", iterations, ms);
}
public static void benchmarkFtpStartup(int iterations) {
long start = System.nanoTime();
for (int i = 0; i < iterations; i++) {
int port = 20000 + (i % 10000);
try (FtpServer server = new FtpServer("127.0.0.1", port, "/tmp")) {
if (server.start() == 0) {
server.stop();
}
} catch (Exception e) {
// Ignore, as ports may be closing
}
}
long end = System.nanoTime();
double ms = (end - start) / 1_000_000.0;
System.out.printf("[Java] FtpServer start/stop (%d iters): %.2f ms\n", iterations, ms);
}
public static void main(String[] args) {
System.out.println("--- Java FFI Benchmarks ---");
benchmarkAllocator(100_000);
benchmarkFtpStartup(1000);
}
}