@@ -0,0 +1,3036 @@
+/*%0A * Licensed to the Apache Software Foundation (ASF) under one or more%0A * contributor license agreements. See the NOTICE file distributed with%0A * this work for additional information regarding copyright ownership.%0A * The ASF licenses this file to You under the Apache license, Version 2.0%0A * (the %22License%22); you may not use this file except in compliance with%0A * the License. You may obtain a copy of the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the license for the specific language governing permissions and%0A * limitations under the license.%0A */%0A%0Apackage org.hipparchus.perf.jmh;%0A%0Aimport java.lang.reflect.Constructor;%0A%0Aimport org.hipparchus.stat.descriptive.StorelessUnivariateStatistic;%0Aimport org.hipparchus.stat.descriptive.moment.Mean;%0Aimport org.openjdk.jmh.annotations.Benchmark;%0Aimport org.openjdk.jmh.annotations.Level;%0Aimport org.openjdk.jmh.annotations.Scope;%0Aimport org.openjdk.jmh.annotations.Setup;%0Aimport org.openjdk.jmh.annotations.State;%0A%0A/**%0A * Tests performance of statistical moments.%0A * The test checks whether using a final Mean instance is still slower%0A * than using a FirstMoment directly. Previously with non-final instances%0A * it was slower as the jvm could not optimize as aggressive as it can with%0A * final instances.%0A */%0A// ============================== HOW TO RUN THIS TEST: ====================================%0A//%0A// single thread:%0A// java -jar perf/target/benchmarks.jar %22.*StatisticalMoment.*%22 -i 10 -f 1 -wi 5 -bm sample -tu ns%0A//%0A// multiple threads (for example, 4 threads):%0A// java -jar perf/target/benchmarks.jar %22.*StatisticalMoment.*%22 -i 10 -f 1 -wi 5 -bm sample -tu ns -t 4%0A//%0A// Usage help:%0A// java -jar perf/target/benchmarks.jar -help%0A//%0A@State(Scope.Thread)%0Apublic class StatisticalMomentBenchmark %7B%0A%0A    StorelessUnivariateStatistic firstMoment;%0A    StorelessUnivariateStatistic meanNormal;%0A    StorelessUnivariateStatistic meanOptimized;%0A%0A    double value = 2.0;%0A%0A    @Setup(Level.Trial)%0A    public void up() %7B%0A        try %7B%0A            // need to get a FirstMoment instance via reflection, as it is package private%0A            Class%3C?%3E firstMomentClass = Class.forName(%22org.hipparchus.stat.descriptive.moment.FirstMoment%22);%0A            Constructor%3C?%3E ctor = firstMomentClass.getDeclaredConstructor();%0A            ctor.setAccessible(true);%0A            firstMoment = (StorelessUnivariateStatistic) ctor.newInstance();%0A        %7D catch (Exception ex) %7B%7D%0A        meanNormal = new Mean();%0A    %7D%0A%0A    @Benchmark%0A    public double baseline() %7B%0A        return value;%0A    %7D%0A%0A    @Benchmark%0A    public double firstMoment() %7B%0A        firstMoment.increment(value);%0A        return firstMoment.getResult();%0A    %7D%0A%0A    @Benchmark%0A    public double meanNormal() %7B%0A        meanNormal.increment(value);%0A        return meanNormal.getResult();%0A    %7D%0A%0A%7D%0A

Add benchmark for statistical moments.