mirror of
https://github.com/wassname/ray.git
synced 2026-07-05 11:59:47 +08:00
[Java] Avoid unnecessary memory copy and addd a benchmark (#4611)
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package org.ray.api.benchmark;
|
||||
|
||||
import org.ray.api.Ray;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class MicroBenchmarks {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(MicroBenchmarks.class);
|
||||
|
||||
public static Object simpleFunction() {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void time(Runnable runnable, int numRepeats, String name) {
|
||||
LOGGER.info("Benchmark \"{}\" started.", name);
|
||||
final long start = System.nanoTime();
|
||||
for (int i = 0; i < numRepeats; i++) {
|
||||
runnable.run();
|
||||
}
|
||||
final long duration = System.nanoTime() - start;
|
||||
LOGGER.info(
|
||||
"Benchmark \"{}\" finished, repeated {} times, total duration {} ms, average duration {} ns.",
|
||||
name, numRepeats, duration / 1_000_000, duration / numRepeats);
|
||||
}
|
||||
|
||||
/**
|
||||
* Benchmark task submission.
|
||||
*
|
||||
* Note, this benchmark is supposed to measure the elapased time in Java worker, we should disable
|
||||
* submitting tasks to raylet in `raylet_client.cc` before running this benchmark.
|
||||
*/
|
||||
public static void benchmarkTaskSubmission() {
|
||||
final int numRepeats = 1_000_000;
|
||||
Ray.init();
|
||||
try {
|
||||
time(() -> {
|
||||
Ray.call(MicroBenchmarks::simpleFunction);
|
||||
}, numRepeats, "task submission");
|
||||
} finally {
|
||||
Ray.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
benchmarkTaskSubmission();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user