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({"100", "1000", "10000", "100000", "1000000"})
60 @Param({"1", "50", "90"})
61 public int startpcnt; // position as percentage of maxcols
63 @Param({"1","15","100"})
66 HiddenColumns h = new HiddenColumns();
67 Random rand = new Random();
69 public int hiddenColumn;
70 public int visibleColumn;
77 while (lastcol < maxcols)
79 int count = rand.nextInt(100);
81 h.hideColumns(lastcol, lastcol+hide);
85 // make sure column at start is hidden
86 hiddenColumn = (int)(maxcols * startpcnt/100.0);
87 h.hideColumns(hiddenColumn, hiddenColumn);
89 // and column <hide> after start is visible
90 ColumnSelection sel = new ColumnSelection();
91 h.revealHiddenColumns(hiddenColumn+hide, sel);
92 visibleColumn = hiddenColumn+hide;
94 System.out.println("Maxcols: " + maxcols + " HiddenCol: " + hiddenColumn + " Hide: " + hide);
95 System.out.println("Number of hidden columns: " + h.getSize());
99 /* Convention: functions in alphabetical order */
102 @BenchmarkMode({Mode.Throughput})
103 public int benchAdjustForHiddenColumns(HiddenColsAndStartState tstate)
105 return tstate.h.visibleToAbsoluteColumn(tstate.visibleColumn);
109 @BenchmarkMode({Mode.Throughput})
110 public int benchFindColumnPosition(HiddenColsAndStartState tstate)
112 return tstate.h.absoluteToVisibleColumn(tstate.visibleColumn);
116 @BenchmarkMode({Mode.Throughput})
117 public int benchGetSize(HiddenColsAndStartState tstate)
119 return tstate.h.getSize();
123 @BenchmarkMode({Mode.Throughput})
124 public HiddenColumns benchHideCols(HiddenColsAndStartState tstate)
126 tstate.h.hideColumns(tstate.visibleColumn,
127 tstate.visibleColumn+2000);
132 @BenchmarkMode({Mode.Throughput})
133 public boolean benchIsVisible(HiddenColsAndStartState tstate)
135 return tstate.h.isVisible(tstate.hiddenColumn);
139 @BenchmarkMode({Mode.Throughput})
140 public HiddenColumns benchReveal(HiddenColsAndStartState tstate)
142 ColumnSelection sel = new ColumnSelection();
143 tstate.h.revealHiddenColumns(tstate.hiddenColumn, sel);
148 @BenchmarkMode({Mode.Throughput})
149 public HiddenColumns benchRevealAll(HiddenColsAndStartState tstate)
151 ColumnSelection sel = new ColumnSelection();
152 tstate.h.revealAllHiddenColumns(sel);