mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
[benchmark] Split benchmarks into separate files (#8351)
Also add Sleipnir cart-pole benchmark from #8323.
This commit is contained in:
@@ -12,44 +12,18 @@ import org.openjdk.jmh.annotations.OutputTimeUnit;
|
||||
import org.openjdk.jmh.profile.GCProfiler;
|
||||
import org.openjdk.jmh.runner.Runner;
|
||||
import org.openjdk.jmh.runner.RunnerException;
|
||||
import org.openjdk.jmh.runner.options.Options;
|
||||
import org.openjdk.jmh.runner.options.OptionsBuilder;
|
||||
import org.openjdk.jmh.runner.options.TimeValue;
|
||||
import org.wpilib.math.geometry.Pose2d;
|
||||
import org.wpilib.math.geometry.Rotation2d;
|
||||
import org.wpilib.math.path.TravelingSalesman;
|
||||
|
||||
public class Main {
|
||||
private static final Pose2d[] poses = {
|
||||
new Pose2d(-1, 1, Rotation2d.kCW_90deg),
|
||||
new Pose2d(-1, 2, Rotation2d.kCCW_90deg),
|
||||
new Pose2d(0, 0, Rotation2d.kZero),
|
||||
new Pose2d(0, 3, Rotation2d.kCW_90deg),
|
||||
new Pose2d(1, 1, Rotation2d.kCCW_90deg),
|
||||
new Pose2d(1, 2, Rotation2d.kCCW_90deg),
|
||||
};
|
||||
private static final int iterations = 100;
|
||||
|
||||
private static final TravelingSalesman transformTraveler =
|
||||
new TravelingSalesman(
|
||||
(pose1, pose2) -> {
|
||||
var transform = pose2.minus(pose1);
|
||||
return Math.hypot(transform.getX(), transform.getY());
|
||||
});
|
||||
private static final TravelingSalesman twistTraveler =
|
||||
new TravelingSalesman(
|
||||
(pose1, pose2) -> {
|
||||
var twist = pose2.minus(pose1).log();
|
||||
return Math.hypot(twist.dx, twist.dy);
|
||||
});
|
||||
|
||||
/**
|
||||
* Main function.
|
||||
*
|
||||
* @param args The (unused) arguments to the program.
|
||||
*/
|
||||
public static void main(String... args) throws RunnerException {
|
||||
Options opt =
|
||||
var opt =
|
||||
new OptionsBuilder()
|
||||
.include(Main.class.getSimpleName())
|
||||
.addProfiler(GCProfiler.class)
|
||||
@@ -66,14 +40,14 @@ public class Main {
|
||||
@Benchmark
|
||||
@BenchmarkMode(Mode.AverageTime)
|
||||
@OutputTimeUnit(TimeUnit.MICROSECONDS)
|
||||
public Pose2d[] transform() {
|
||||
return transformTraveler.solve(poses, iterations);
|
||||
public Pose2d[] travelingSalesmanTransform() {
|
||||
return TravelingSalesmanBenchmark.transform();
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
@BenchmarkMode(Mode.AverageTime)
|
||||
@OutputTimeUnit(TimeUnit.MICROSECONDS)
|
||||
public Pose2d[] twist() {
|
||||
return twistTraveler.solve(poses, iterations);
|
||||
public Pose2d[] travelingSalesmanTwist() {
|
||||
return TravelingSalesmanBenchmark.twist();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user