All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cz.cuni.mff.d3s.spl.data.BenchmarkRunSummary Maven / Gradle / Ivy

Go to download

Stochastice Performance Logic is a formalism for capturing performance assumptions. It is, for example, possible to capture assumption that newer version of a function bar is faster than the previous version or that library foobar is faster than library barfoo when rendering antialiased text. The purpose of this framework is to allow evaluation of SPL formulas inside Java applications.

There is a newer version: 1.0.4
Show newest version
/*
 * Copyright 2015 Charles University in Prague
 * Copyright 2015 Vojtech Horky
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package cz.cuni.mff.d3s.spl.data;

import org.apache.commons.math3.stat.descriptive.moment.Mean;
import org.apache.commons.math3.stat.descriptive.moment.Variance;

/** Statistical summary of a benchmark run.
 * 
 * 

* This class aggregates the whole benchmark run into few values such as * mean, variance or number of data samples. * *

* This class is in essence immutable but it uses caching to improve * performance (hopefully). * Also, it makes copy of the original benchmark run and the changes in * the original run are not taken into account when user retrieves the values. */ public class BenchmarkRunSummary { private final double[] data; private Double cacheMean = null; private Double cacheVariance = null; /** Create a new summary from a benchmark run. * *

* The data from the given run are copied and further changes to the * run are ignored when the statistical values are retrived. * * @param run Benchmark run from which to compute the summary. */ public BenchmarkRunSummary(BenchmarkRun run) { synchronized (run) { data = new double[run.getSampleCount()]; for (int i = 0; i < data.length; i++) { data[i] = run.getSample(i); } } } /** Compute artihmetic mean of the samples. * * @return Arithmetic mean of the data in the original benchmark run. */ public synchronized double getMean() { if (cacheMean == null) { Mean mean = new Mean(); cacheMean = mean.evaluate(data); } return cacheMean; } /** Compute variance of the samples. * * @return Variance of the data in the original benchmark run. */ public synchronized double getVariance() { if (cacheVariance == null) { Variance mean = new Variance(); cacheVariance = mean.evaluate(data); } return cacheVariance; } /** Tell number of data samples. * * @return Number of samples in the original benchmark run. */ public long getSize() { return data.length; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy