2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
24 import org.openjdk.jmh.annotations.Benchmark;
25 import org.openjdk.jmh.annotations.BenchmarkMode;
26 import org.openjdk.jmh.annotations.Fork;
27 import org.openjdk.jmh.annotations.Measurement;
28 import org.openjdk.jmh.annotations.Mode;
29 import org.openjdk.jmh.annotations.Setup;
30 import org.openjdk.jmh.annotations.State;
31 import org.openjdk.jmh.annotations.Warmup;
32 import org.openjdk.jmh.annotations.Scope;
33 import org.openjdk.jmh.annotations.Param;
35 import java.util.ArrayList;
36 import java.util.List;
37 import java.util.Random;
38 import java.util.concurrent.TimeUnit;
40 import jalview.datamodel.ColumnSelection;
41 import jalview.datamodel.HiddenColumns;
44 * A class to benchmark hidden columns performance
46 @Warmup(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS)
47 @Measurement(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS)
49 public class HiddenColumnsBenchmark
52 * State with multiple hidden columns and a start position set
55 public static class HiddenColsAndStartState
57 @Param({ "300", "10000", "100000" })
60 @Param({ "1", "50", "90" })
61 public int startpcnt; // position as percentage of maxcols
63 @Param({ "1", "15", "100" })
66 HiddenColumns h = new HiddenColumns();
68 Random rand = new Random();
70 public int hiddenColumn;
72 public int visibleColumn;
79 while (lastcol < maxcols)
81 int count = rand.nextInt(100);
83 h.hideColumns(lastcol, lastcol + hide);
87 // make sure column at start is hidden
88 hiddenColumn = (int) (maxcols * startpcnt / 100.0);
89 h.hideColumns(hiddenColumn, hiddenColumn);
91 // and column <hide> after start is visible
92 ColumnSelection sel = new ColumnSelection();
93 h.revealHiddenColumns(hiddenColumn + hide, sel);
94 visibleColumn = hiddenColumn + hide;
96 System.out.println("Maxcols: " + maxcols + " HiddenCol: "
97 + hiddenColumn + " Hide: " + hide);
98 System.out.println("Number of hidden columns: " + h.getSize());
102 /* Convention: functions in alphabetical order */
105 @BenchmarkMode({ Mode.Throughput })
106 public int benchAdjustForHiddenColumns(HiddenColsAndStartState tstate)
108 return tstate.h.adjustForHiddenColumns(tstate.visibleColumn);
112 @BenchmarkMode({ Mode.Throughput })
113 public int benchFindColumnPosition(HiddenColsAndStartState tstate)
115 return tstate.h.findColumnPosition(tstate.visibleColumn);
119 @BenchmarkMode({ Mode.Throughput })
120 public List<Integer> benchFindHiddenRegionPositions(
121 HiddenColsAndStartState tstate)
123 return tstate.h.findHiddenRegionPositions();
127 @BenchmarkMode({ Mode.Throughput })
128 public ArrayList<int[]> benchGetHiddenColumnsCopy(
129 HiddenColsAndStartState tstate)
131 return tstate.h.getHiddenColumnsCopy();
135 @BenchmarkMode({ Mode.Throughput })
136 public int benchGetSize(HiddenColsAndStartState tstate)
138 return tstate.h.getSize();
142 @BenchmarkMode({ Mode.Throughput })
143 public HiddenColumns benchHideCols(HiddenColsAndStartState tstate)
145 tstate.h.hideColumns(tstate.visibleColumn, tstate.visibleColumn + 2000);
150 @BenchmarkMode({ Mode.Throughput })
151 public boolean benchIsVisible(HiddenColsAndStartState tstate)
153 return tstate.h.isVisible(tstate.hiddenColumn);
157 @BenchmarkMode({ Mode.Throughput })
158 public HiddenColumns benchReveal(HiddenColsAndStartState tstate)
160 ColumnSelection sel = new ColumnSelection();
161 tstate.h.revealHiddenColumns(tstate.hiddenColumn, sel);
166 @BenchmarkMode({ Mode.Throughput })
167 public HiddenColumns benchRevealAll(HiddenColsAndStartState tstate)
169 ColumnSelection sel = new ColumnSelection();
170 tstate.h.revealAllHiddenColumns(sel);