File tree Expand file tree Collapse file tree 2 files changed +69
-4
lines changed Expand file tree Collapse file tree 2 files changed +69
-4
lines changed Original file line number Diff line number Diff line change 7
7
# - Do the same for master
8
8
# - then compare the two runs with benchcmp
9
9
10
- if [ $# -ne 2 ]
10
+ benchFilter=" .*"
11
+
12
+ if (( $# < 2 )) ;
11
13
then
12
- echo " USAGE: ./bench.sh <git-branch> <package-to-bench>"
14
+ echo " USAGE: ./bench.sh <git-branch> <package-to-bench> (and <benchmark filter> (regexp, optional)) "
13
15
exit 1
14
16
fi
15
17
16
18
19
+
20
+ if [ $# -eq 3 ]; then
21
+ benchFilter=$3
22
+ fi
23
+
24
+
17
25
BRANCH=$1
18
26
PACKAGE=$2
19
27
20
28
git checkout $BRANCH
21
- go test -test.run=NONE -bench=" .* " -test.benchmem=true ./$PACKAGE > /tmp/bench-$PACKAGE -$BRANCH .txt
29
+ go test -test.run=NONE -bench=" $benchFilter " -test.benchmem=true ./$PACKAGE > /tmp/bench-$PACKAGE -$BRANCH .txt
22
30
23
31
git checkout master
24
- go test -test.run=NONE -bench=" .* " -test.benchmem=true ./$PACKAGE > /tmp/bench-$PACKAGE -master.txt
32
+ go test -test.run=NONE -bench=" $benchFilter " -test.benchmem=true ./$PACKAGE > /tmp/bench-$PACKAGE -master.txt
25
33
26
34
27
35
benchcmp /tmp/bench-$PACKAGE -master.txt /tmp/bench-$PACKAGE -$BRANCH .txt
Original file line number Diff line number Diff line change
1
+ package hugolib
2
+
3
+ import (
4
+ "fmt"
5
+ "github.com/stretchr/testify/assert"
6
+ "path/filepath"
7
+ "testing"
8
+
9
+ "github.com/spf13/hugo/source"
10
+ )
11
+
12
+ func TestPageSortReverse (t * testing.T ) {
13
+ p := createSortTestPages (10 )
14
+ assert .Equal (t , 0 , p [0 ].FuzzyWordCount )
15
+ assert .Equal (t , 9 , p [9 ].FuzzyWordCount )
16
+ p = p .Reverse ()
17
+ assert .Equal (t , 9 , p [0 ].FuzzyWordCount )
18
+ assert .Equal (t , 1 , p [9 ].FuzzyWordCount )
19
+ }
20
+
21
+ func BenchmarkSortByWeightAndReverse (b * testing.B ) {
22
+
23
+ p := createSortTestPages (300 )
24
+
25
+ b .ResetTimer ()
26
+ for i := 0 ; i < b .N ; i ++ {
27
+ p = p .ByWeight ().Reverse ()
28
+ }
29
+
30
+ }
31
+
32
+ func createSortTestPages (num int ) Pages {
33
+ pages := make (Pages , num )
34
+
35
+ for i := 0 ; i < num ; i ++ {
36
+ pages [i ] = & Page {
37
+ Node : Node {
38
+ URLPath : URLPath {
39
+ Section : "z" ,
40
+ URL : fmt .Sprintf ("http://base/x/y/p%d.html" , i ),
41
+ },
42
+ Site : & SiteInfo {
43
+ BaseURL : "http://base/" ,
44
+ },
45
+ },
46
+ Source : Source {File : * source .NewFile (filepath .FromSlash (fmt .Sprintf ("/x/y/p%d.md" , i )))},
47
+ }
48
+ w := 5
49
+ if i % 2 == 0 {
50
+ w = 10
51
+ }
52
+ pages [i ].FuzzyWordCount = i
53
+ pages [i ].Weight = w
54
+ }
55
+
56
+ return pages
57
+ }
You can’t perform that action at this time.
0 commit comments