<dependency> <groupId>com.github.nscala-time</groupId> <artifactId>nscala-time_2.13</artifactId> <version>2.28.0</version> </dependency> import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.Level; import org.openjdk.jmh.annotations.Setup; import org.openjdk.jmh.infra.Blackhole; import scalaj.time.Imports.*; public class ScalajTimeBenchmark { private DateTime dateTime; @Setup(Level.Iteration) public void setup() { dateTime = DateTime.now(); } @Benchmark public void createDateTimeBenchmark(Blackhole bh) { bh.consume(new DateTime()); } @Benchmark public void calculateDifferenceBenchmark(Blackhole bh) { DateTime otherDateTime = dateTime.plusDays(5); bh.consume(Days.daysBetween(dateTime, otherDateTime).getDays()); } } bash java -jar target/benchmarks.jar


上一篇:
下一篇:
切换中文