You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by re...@apache.org on 2020/11/04 07:19:56 UTC
[uima-uimafit] branch
feature/UIMA-6291-Improve-uimaFIT-benchmarking-module updated: [UIMA-6291]
Improve uimaFIT benchmarking module
This is an automated email from the ASF dual-hosted git repository.
rec pushed a commit to branch feature/UIMA-6291-Improve-uimaFIT-benchmarking-module
in repository https://gitbox.apache.org/repos/asf/uima-uimafit.git
The following commit(s) were added to refs/heads/feature/UIMA-6291-Improve-uimaFIT-benchmarking-module by this push:
new f1a8f6f [UIMA-6291] Improve uimaFIT benchmarking module
f1a8f6f is described below
commit f1a8f6f9756c868726f7cf262ff801494c8e0004
Author: Richard Eckart de Castilho <re...@apache.org>
AuthorDate: Wed Nov 4 08:10:31 2020 +0100
[UIMA-6291] Improve uimaFIT benchmarking module
- Added support for benchmark groups
- Avoid re-building the CAS for every single benchmark to make benchmarks in a group more comparable
- Provide informative summaries for groups
---
.../apache/uima/fit/benchmark/BenchmarkGroup.java | 58 ++++++++++++++++++++++
.../fit/benchmark/CachingRandomJCasProvider.java | 57 +++++++++++++++++++++
2 files changed, 115 insertions(+)
diff --git a/uimafit-benchmark/src/main/java/org/apache/uima/fit/benchmark/BenchmarkGroup.java b/uimafit-benchmark/src/main/java/org/apache/uima/fit/benchmark/BenchmarkGroup.java
new file mode 100644
index 0000000..e6bf4e9
--- /dev/null
+++ b/uimafit-benchmark/src/main/java/org/apache/uima/fit/benchmark/BenchmarkGroup.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.uima.fit.benchmark;
+
+import static java.util.Comparator.comparing;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class BenchmarkGroup {
+ private final String name;
+ private final List<Benchmark> benchmarks = new ArrayList<>();
+
+ public BenchmarkGroup(String aName) {
+ name = aName;
+ }
+
+ public BenchmarkGroup add(Benchmark aBenchmark) {
+ benchmarks.add(aBenchmark);
+ return this;
+ }
+
+ public void runAll() {
+ System.out.printf(">>>>>>>>>>>>>>>>>>%n");
+ System.out.printf("GROUP: %s%n", name);
+
+ for (Benchmark benchmark : benchmarks) {
+ benchmark.run();
+ }
+
+ System.out.printf("%n%nSorted by execution time:%n");
+ benchmarks.stream()
+ .sorted(comparing(Benchmark::getCumulativeDuration))
+ .forEach(benchmark -> {
+ Measurement slowest = benchmark.getSlowestMeasurement();
+ System.out.printf("%6dms / %4dms -- %s%n", benchmark.getCumulativeDuration(), slowest.getDuration(),
+ benchmark.getName());
+ });
+
+ System.out.printf(">>>>>>>>>>>>>>>>>>%n%n");
+ }
+}
diff --git a/uimafit-benchmark/src/main/java/org/apache/uima/fit/benchmark/CachingRandomJCasProvider.java b/uimafit-benchmark/src/main/java/org/apache/uima/fit/benchmark/CachingRandomJCasProvider.java
new file mode 100644
index 0000000..1272dd4
--- /dev/null
+++ b/uimafit-benchmark/src/main/java/org/apache/uima/fit/benchmark/CachingRandomJCasProvider.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.uima.fit.benchmark;
+
+import static org.apache.uima.fit.benchmark.CasInitializationUtils.initRandomCas;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.uima.cas.CASException;
+import org.apache.uima.fit.factory.JCasFactory;
+import org.apache.uima.jcas.JCas;
+import org.apache.uima.resource.ResourceInitializationException;
+
+public class CachingRandomJCasProvider {
+ private static final long RANDOM_SEED = 12345l;
+
+ private final Map<Integer, JCas> cache = new HashMap<>();
+
+ private JCas preparedJCas;
+
+ public void prepare(int size) {
+ JCas cachedJCas = cache.get(size);
+
+ if (cachedJCas == null) {
+ try {
+ cachedJCas = JCasFactory.createJCas();
+ } catch (ResourceInitializationException | CASException e) {
+ throw new RuntimeException(e);
+ }
+
+ initRandomCas(cachedJCas.getCas(), size, RANDOM_SEED);
+ cache.put(size, cachedJCas);
+ }
+
+ preparedJCas = cachedJCas;
+ }
+
+ public JCas get() {
+ return preparedJCas;
+ }
+}