Merge branch 'Jalview-JS/jim/JAL-3253-JAL-3418' into Jalview-JS/JAL-3253-applet
[jalview.git] / benchmarking / src / main / java / org / jalview / SeqWidthBenchmark.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
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.
11  *  
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.
16  * 
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.
20  */
21
22 package org.jalview;
23
24 import org.jalview.HiddenColumnsBenchmark.HiddenColsAndStartState;
25 import org.openjdk.jmh.annotations.Benchmark;
26 import org.openjdk.jmh.annotations.BenchmarkMode;
27 import org.openjdk.jmh.annotations.Fork;
28 import org.openjdk.jmh.annotations.Measurement;
29 import org.openjdk.jmh.annotations.Mode;
30 import org.openjdk.jmh.annotations.Setup;
31 import org.openjdk.jmh.annotations.State;
32 import org.openjdk.jmh.annotations.Warmup;
33 import org.openjdk.jmh.annotations.Scope;
34 import org.openjdk.jmh.annotations.Param;
35
36 import java.util.ArrayList;
37 import java.util.List;
38 import java.util.Random;
39 import java.util.concurrent.TimeUnit;
40
41 import jalview.datamodel.Alignment;
42 import jalview.datamodel.AlignmentI;
43 import jalview.datamodel.Sequence;
44 import jalview.datamodel.SequenceI;
45
46 /*
47  * A class to benchmark hidden columns performance
48  */
49 @Warmup(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS)
50 @Measurement(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS)
51 @Fork(1)
52 public class SeqWidthBenchmark {
53
54         /*
55          * State with multiple hidden columns and a start position set
56          */
57         @State(Scope.Thread)
58         public static class AlignmentState
59         {
60                 @Param({"100", "1000", "10000", "100000"})
61                 public int numSeqs;
62                 
63                 Random rand = new Random();
64                 
65                 AlignmentI al;
66                 
67                 @Setup
68                 public void setup()
69                 {
70                         rand.setSeed(1234);
71                         
72                         SequenceI[] seqs = new Sequence[numSeqs];
73                     for (int i = 0; i < numSeqs; i++)
74                     {
75                       int count = rand.nextInt(10000); 
76                       StringBuilder aas = new StringBuilder();
77                       for (int j=0; j<count; j++)
78                       {
79                          aas.append("a");
80                       }
81
82                       seqs[i] = new Sequence("Sequence" + i, aas.toString());
83                     }
84                         al = new Alignment(seqs);
85                 }
86         }
87         
88         
89         @Benchmark
90         @BenchmarkMode({Mode.Throughput})
91         public int benchSeqGetWidth(AlignmentState tstate)
92         {
93                 return tstate.al.getWidth();
94         }
95         
96 }