当前位置: 首页>>代码示例>>Java>>正文


Java BenchmarkResult类代码示例

本文整理汇总了Java中org.openjdk.jmh.results.BenchmarkResult的典型用法代码示例。如果您正苦于以下问题:Java BenchmarkResult类的具体用法?Java BenchmarkResult怎么用?Java BenchmarkResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


BenchmarkResult类属于org.openjdk.jmh.results包,在下文中一共展示了BenchmarkResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: afterTrial

import org.openjdk.jmh.results.BenchmarkResult; //导入依赖的package包/类
@Override
public Collection<? extends Result> afterTrial(BenchmarkResult benchmarkResult, long l, File stdOut, File stdErr) {
    String target = Paths.get(SAVE_FLIGHT_OUTPUT_TO).resolve(benchmarkResult.getParams().getBenchmark() + "-" + currentId++ + ".jfr").toAbsolutePath().toString();

    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);

    try {
        FileUtils.copy(jfrData, target);
        pw.println("Flight Recording output saved to " + target);
    } catch (IOException e) {
        e.printStackTrace();
        pw.println("Unable to save flight output to " + target);
        pw.println("Did you miss the system property: -Djmh.jfr.saveTo ?");
    }

    pw.flush();
    pw.close();

    NoResult r = new NoResult(sw.toString());

    return Collections.singleton(r);
}
 
开发者ID:biboudis,项目名称:jmh-profilers,代码行数:24,代码来源:FlightRecordingProfiler.java

示例2: runBenchmark

import org.openjdk.jmh.results.BenchmarkResult; //导入依赖的package包/类
BenchmarkResult runBenchmark(BenchmarkParams benchParams) {
    BenchmarkHandler handler = null;
    try {
        String target = benchParams.generatedBenchmark();
        int lastDot = target.lastIndexOf('.');
        Class<?> clazz = ClassUtils.loadClass(target.substring(0, lastDot));
        Method method = BenchmarkHandlers.findBenchmarkMethod(clazz, target.substring(lastDot + 1));

        handler = BenchmarkHandlers.getInstance(out, clazz, method, benchParams, options);

        return runBenchmark(benchParams, handler);
    } catch (BenchmarkException be) {
        throw be;
    } catch (Throwable ex) {
        throw new BenchmarkException(ex);
    } finally {
        if (handler != null) {
            handler.shutdown();
        }
    }
}
 
开发者ID:msteindorfer,项目名称:jmh,代码行数:22,代码来源:BaseRunner.java

示例3: createMockedRunResult

import org.openjdk.jmh.results.BenchmarkResult; //导入依赖的package包/类
private RunResult createMockedRunResult(final double value) {
	final IterationResult iterationResult = new IterationResult(null, null, null);
	iterationResult.addResult(new SingleShotResult(ResultRole.PRIMARY, "", (long) value, TimeUnit.NANOSECONDS));
	final Collection<IterationResult> iterationResults = Arrays.asList(iterationResult);
	final BenchmarkResult benchmarkResult = new BenchmarkResult(null, iterationResults);
	final Collection<BenchmarkResult> benchmarkResults = Arrays.asList(benchmarkResult);
	return new RunResult(null, benchmarkResults);
}
 
开发者ID:SoerenHenning,项目名称:RadarGun,代码行数:9,代码来源:TestResultFactoryTest.java

示例4: run

import org.openjdk.jmh.results.BenchmarkResult; //导入依赖的package包/类
public void run() throws IOException, ClassNotFoundException {
    ActionPlan actionPlan = link.requestPlan();

    try {
        Multimap<BenchmarkParams,BenchmarkResult> res = runBenchmarks(true, actionPlan);
        link.pushResults(res);
    } catch (BenchmarkException be) {
        link.pushException(be);
    }

    out.flush();
    out.close();
}
 
开发者ID:msteindorfer,项目名称:jmh,代码行数:14,代码来源:ForkedRunner.java

示例5: runBenchmarks

import org.openjdk.jmh.results.BenchmarkResult; //导入依赖的package包/类
private Collection<RunResult> runBenchmarks(SortedSet<BenchmarkListEntry> benchmarks) throws RunnerException {
    out.startRun();

    Multimap<BenchmarkParams, BenchmarkResult> results = new TreeMultimap<BenchmarkParams, BenchmarkResult>();
    List<ActionPlan> plan = getActionPlans(benchmarks);

    etaBeforeBenchmarks(plan);

    try {
        for (ActionPlan r : plan) {
            Multimap<BenchmarkParams, BenchmarkResult> res;
            switch (r.getType()) {
                case EMBEDDED:
                    res = runBenchmarks(false, r);
                    break;
                case FORKED:
                    res = runSeparate(r);
                    break;
                default:
                    throw new IllegalStateException("Unknown action plan type: " + r.getType());
            }

            for (BenchmarkParams br : res.keys()) {
                results.putAll(br, res.get(br));
            }
        }

        etaAfterBenchmarks();

        SortedSet<RunResult> runResults = mergeRunResults(results);
        out.endRun(runResults);
        return runResults;
    } catch (BenchmarkException be) {
        throw new RunnerException("Benchmark caught the exception", be.getCause());
    }
}
 
开发者ID:msteindorfer,项目名称:jmh,代码行数:37,代码来源:Runner.java

示例6: mergeRunResults

import org.openjdk.jmh.results.BenchmarkResult; //导入依赖的package包/类
private SortedSet<RunResult> mergeRunResults(Multimap<BenchmarkParams, BenchmarkResult> results) {
    SortedSet<RunResult> result = new TreeSet<RunResult>(RunResult.DEFAULT_SORT_COMPARATOR);
    for (BenchmarkParams key : results.keys()) {
        result.add(new RunResult(results.get(key)));
    }
    return result;
}
 
开发者ID:msteindorfer,项目名称:jmh,代码行数:8,代码来源:Runner.java

示例7: BinaryLinkServer

import org.openjdk.jmh.results.BenchmarkResult; //导入依赖的package包/类
public BinaryLinkServer(Options opts, OutputFormat out) throws IOException {
    this.opts = opts;
    this.out = out;
    this.methods = new HashMap<String, Method>();
    this.forbidden = new HashSet<String>();

    // enumerate methods
    for (Method m : OutputFormat.class.getMethods()) {

        // start/end run callbacks are banned, since their effects are enforced by parent instead
        if (m.getName().equals("startRun")) { forbidden.add(ClassConventions.getMethodName(m)); }
        if (m.getName().equals("endRun"))   { forbidden.add(ClassConventions.getMethodName(m)); }

        Method prev = methods.put(ClassConventions.getMethodName(m), m);
        if (prev != null) {
            out.println("WARNING: Duplicate methods: " + m + " vs. " + prev);
            throw new IllegalStateException("WARNING: Duplicate methods: " + m + " vs. " + prev);
        }
    }

    acceptor = new Acceptor();
    acceptor.start();

    handler = new AtomicReference<Handler>();
    results = new AtomicReference<Multimap<BenchmarkParams, BenchmarkResult>>(new HashMultimap<BenchmarkParams, BenchmarkResult>());
    exception = new AtomicReference<BenchmarkException>();
    plan = new AtomicReference<ActionPlan>();
}
 
开发者ID:msteindorfer,项目名称:jmh,代码行数:29,代码来源:BinaryLinkServer.java

示例8: getResults

import org.openjdk.jmh.results.BenchmarkResult; //导入依赖的package包/类
public Multimap<BenchmarkParams, BenchmarkResult> getResults() {
    Multimap<BenchmarkParams, BenchmarkResult> res = results.getAndSet(new HashMultimap<BenchmarkParams, BenchmarkResult>());
    if (res != null) {
        return res;
    } else {
        throw new IllegalStateException("Acquiring the null result");
    }
}
 
开发者ID:msteindorfer,项目名称:jmh,代码行数:9,代码来源:BinaryLinkServer.java

示例9: endBenchmark

import org.openjdk.jmh.results.BenchmarkResult; //导入依赖的package包/类
@Override
public void endBenchmark(BenchmarkResult result) {
    out.println();
    if (result != null) {
        out.println(result.getPrimaryResult().extendedInfo(null));
        for (Result r : result.getSecondaryResults().values()) {
            out.println(r.extendedInfo(r.getLabel()));
        }
        out.println();
    }
}
 
开发者ID:msteindorfer,项目名称:jmh,代码行数:12,代码来源:TextReportFormat.java

示例10: getTimes

import org.openjdk.jmh.results.BenchmarkResult; //导入依赖的package包/类
private List<Double> getTimes(String algorithmId,
                              String datasetId,
                              int warmUps,
                              int measurements) throws CLIWrapperException, RunnerException {
    Options options = new OptionsBuilder()
            .forks(1)
            .measurementIterations(measurements)
            .warmupIterations(warmUps)
            .param("datasetId", datasetId)
            .param("algorithmId", algorithmId)
            .include(JMHBenchmark.class.getName())
            .build();

    Collection<RunResult> results = new Runner(options).run();
    List<Double> times = new ArrayList<>();
    for (RunResult result : results) {
        for (BenchmarkResult benchmarkResult : result.getBenchmarkResults()) {
            BenchmarkParams params = benchmarkResult.getParams();
            String myDatasetId = params.getParam("datasetId");
            if (!datasetId.equals(myDatasetId)) {
                throw new CLIWrapperException("Unable to dig through JMH output: Value for 'datasetId' parameter is '"
                        + myDatasetId + "' but expected '" + datasetId + "'", null);
            }
            String myAlgorithmId = params.getParam("algorithmId");
            if (!algorithmId.equals(myAlgorithmId)) {
                throw new CLIWrapperException("Unable to dig through JMH output: Value for 'algorithmId' parameter is '"
                        + myAlgorithmId + "' but expected '" + algorithmId + "'", null);
            }
            int count = 0;
            for (IterationResult iterationResult : benchmarkResult.getIterationResults()) {
                for (Result<?> primary : iterationResult.getRawPrimaryResults()) {
                    if (primary.getStatistics().getN() != 1) {
                        throw new CLIWrapperException("Unable to dig through JMH output: getN() != 1", null);
                    }
                    if (!primary.getScoreUnit().equals("us/op")) {
                        throw new CLIWrapperException("Unable to dig through JMH output: getScoreUnit() = " + primary.getScoreUnit(), null);
                    }
                    double value = primary.getScore() / 1e6;
                    times.add(value / IdCollection.getDataset(datasetId).getNumberOfInstances());
                    ++count;
                }
            }
            if (count != measurements) {
                throw new CLIWrapperException("Unable to dig through JMH output: Expected "
                        + measurements + " measurements, found " + count, null);
            }
        }
    }
    return times;
}
 
开发者ID:mbuzdalov,项目名称:non-dominated-sorting,代码行数:51,代码来源:Benchmark.java

示例11: afterTrial

import org.openjdk.jmh.results.BenchmarkResult; //导入依赖的package包/类
@Override
public Collection<? extends Result> afterTrial(BenchmarkResult br, long pid, File stdOut, File stdErr) {
    return Collections.emptyList();
}
 
开发者ID:cglib,项目名称:cglib,代码行数:5,代码来源:FlightRecorderProfiler.java

示例12: pushResults

import org.openjdk.jmh.results.BenchmarkResult; //导入依赖的package包/类
public void pushResults(Multimap<BenchmarkParams, BenchmarkResult> res) throws IOException {
    pushFrame(new ResultsFrame(res));
}
 
开发者ID:msteindorfer,项目名称:jmh,代码行数:4,代码来源:BinaryLinkClient.java

示例13: ResultsFrame

import org.openjdk.jmh.results.BenchmarkResult; //导入依赖的package包/类
public ResultsFrame(Multimap<BenchmarkParams, BenchmarkResult> res) {
    this.res = res;
}
 
开发者ID:msteindorfer,项目名称:jmh,代码行数:4,代码来源:ResultsFrame.java

示例14: getRes

import org.openjdk.jmh.results.BenchmarkResult; //导入依赖的package包/类
public Multimap<BenchmarkParams, BenchmarkResult> getRes() {
    return res;
}
 
开发者ID:msteindorfer,项目名称:jmh,代码行数:4,代码来源:ResultsFrame.java

示例15: runBenchmarks

import org.openjdk.jmh.results.BenchmarkResult; //导入依赖的package包/类
protected Multimap<BenchmarkParams, BenchmarkResult> runBenchmarks(boolean forked, ActionPlan actionPlan) {
    Multimap<BenchmarkParams, BenchmarkResult> results = new TreeMultimap<BenchmarkParams, BenchmarkResult>();

    for (Action action : actionPlan.getActions()) {

        BenchmarkParams params = action.getParams();
        ActionMode mode = action.getMode();

        if (!forked) {
            String opts = Utils.join(params.getJvmArgs(), " ").trim();
            String realOpts = Utils.join(ManagementFactory.getRuntimeMXBean().getInputArguments(), " ").trim();
            if (opts.isEmpty()) {
                opts = "<none>";
            }
            if (realOpts.isEmpty()) {
                realOpts = "<none>";
            }

            Version.printVersion(out);
            out.println("# VM invoker: " + params.getJvm());
            out.println("# VM invoker: " + params.getJvm());
            out.println("# VM options: " + realOpts + (opts.equals(realOpts) ? "" : " *** WARNING: some JVM options are ignored in non-forked runs ***"));

            out.startBenchmark(params);
            out.println("");
            etaBeforeBenchmark();
            out.println("# Fork: N/A, test runs in the existing VM");
        }

        BenchmarkResult r = null;
        try {
            switch (mode) {
                case WARMUP: {
                    runBenchmark(params);
                    out.println("");
                    break;
                }
                case WARMUP_MEASUREMENT:
                case MEASUREMENT: {
                    r = runBenchmark(params);
                    results.put(params, r);
                    break;
                }
                default:
                    throw new IllegalStateException("Unknown mode: " + mode);

            }
        } catch (BenchmarkException be) {
            out.println("<failure>");
            out.println("");
            out.println(Utils.throwableToString(be.getCause()));
            out.println("");

            if (options.shouldFailOnError().orElse(Defaults.FAIL_ON_ERROR)) {
                throw be;
            }
        }

        if (!forked) {
            etaAfterBenchmark(params);
            out.endBenchmark(r);
        }
    }

    return results;
}
 
开发者ID:msteindorfer,项目名称:jmh,代码行数:67,代码来源:BaseRunner.java


注:本文中的org.openjdk.jmh.results.BenchmarkResult类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。