github.com/meulengracht/snapd@v0.0.0-20210719210640-8bde69bcc84e/strutil/version_benchmark_test.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2014-2018 Canonical Ltd
     5   *
     6   * This program is free software: you can redistribute it and/or modify
     7   * it under the terms of the GNU General Public License version 3 as
     8   * published by the Free Software Foundation.
     9   *
    10   * This program is distributed in the hope that it will be useful,
    11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13   * GNU General Public License for more details.
    14   *
    15   * You should have received a copy of the GNU General Public License
    16   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    17   *
    18   */
    19  
    20  package strutil_test
    21  
    22  import (
    23  	"testing"
    24  
    25  	"github.com/snapcore/snapd/strutil"
    26  )
    27  
    28  var versions = []string{
    29  	"~",
    30  	"",
    31  	"0",
    32  	"00",
    33  	"009",
    34  	"009ab5",
    35  	"0.10.0",
    36  	"0.2",
    37  	"0.4",
    38  	"0.4-1",
    39  	"0.4a6",
    40  	"0.4a6-2",
    41  	"0.5.0~git",
    42  	"0.5.0~git2",
    43  	"0.8.7",
    44  	"0-pre",
    45  	"0pre",
    46  	"0-pree",
    47  	"0pree",
    48  	"1.0~",
    49  	"1.0",
    50  	"1.0-0~",
    51  	"1.0-0",
    52  	"1.00",
    53  	"1.002-1+b2",
    54  	"1.0-0+b1",
    55  	"1.0-1",
    56  	"1.0-1.1",
    57  	"1.0-2",
    58  	"1.1.6r-1",
    59  	"1.1.6r2-2",
    60  	"1.18.36:5.4",
    61  	"1.18.36:5.5",
    62  	"1.18.37:1.1",
    63  	"1.2.2.2",
    64  	"1.2.24",
    65  	"1.2.3",
    66  	"1.2.3-0",
    67  	"1.2.3-1",
    68  	"1.2.4",
    69  	"1.2a+~",
    70  	"1.2a++",
    71  	"1.2a+~bCd3",
    72  	"1.3",
    73  	"1.3.1",
    74  	"1.3.2",
    75  	"1.3.2a",
    76  	"1.4+OOo3.0.0~",
    77  	"1.4+OOo3.0.0-4",
    78  	"2.0",
    79  	"2.0.7pre1",
    80  	"2.0.7r",
    81  	"21",
    82  	"2.3",
    83  	"2.4.7-1",
    84  	"2.4.7-z",
    85  	"2.6b-2",
    86  	"2.6b2-1",
    87  	"2a",
    88  	"3.0-1",
    89  	"3.0~rc1-1",
    90  	"3~10",
    91  	"3.10.2",
    92  	"3.2",
    93  	"3a9.8",
    94  	"4.4.3-2",
    95  	"5.005",
    96  	"5.10.0",
    97  	"7.2",
    98  	"7.2p2",
    99  	"9",
   100  	"9ab5",
   101  }
   102  
   103  func BenchmarkVersionCompare(b *testing.B) {
   104  	for n := 0; n < b.N; n++ {
   105  		for i := range versions {
   106  			for j := range versions {
   107  				strutil.VersionCompare(versions[i], versions[j])
   108  			}
   109  		}
   110  	}
   111  }