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.infra.Blackhole;
33 import org.openjdk.jmh.annotations.Scope;
34 import org.openjdk.jmh.annotations.Param;
36 import java.util.Iterator;
37 import java.util.List;
38 import java.util.Random;
39 import java.util.concurrent.TimeUnit;
41 import jalview.datamodel.ColumnSelection;
42 import jalview.datamodel.HiddenColumns;
45 * A class to benchmark hidden columns performance
47 @Warmup(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS)
48 @Measurement(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS)
50 public class HiddenColsIteratorsBenchmark {
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();
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 benchStartIterator(HiddenColsAndStartState tstate)
106 int startx = tstate.visibleColumn;
107 Iterator<Integer> it = tstate.h.getStartRegionIterator(startx,
111 res = it.next() - startx;
112 Blackhole.consumeCPU(5);
118 @BenchmarkMode({Mode.Throughput})
119 public int benchBoundedIterator(HiddenColsAndStartState tstate)
121 int startx = tstate.visibleColumn;
122 int blockStart = startx;
125 Iterator<int[]> it = tstate.h.getBoundedIterator(startx,
129 int[] region = it.next();
131 blockEnd = Math.min(region[0] - 1, blockStart + 60 - screenY);
133 screenY += blockEnd - blockStart + 1;
134 blockStart = region[1] + 1;
136 Blackhole.consumeCPU(5);