-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbenchmark_test.go
More file actions
68 lines (57 loc) · 2 KB
/
benchmark_test.go
File metadata and controls
68 lines (57 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package wrap_test
import (
"testing"
"github.com/bbrks/wrap/v2"
)
func benchmarkWrap(b *testing.B, limit int) {
w := wrap.NewWrapper()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
w.Wrap(loremIpsums[0], limit)
}
}
func BenchmarkWrap0(b *testing.B) { benchmarkWrap(b, 0) }
func BenchmarkWrap1(b *testing.B) { benchmarkWrap(b, 1) }
func BenchmarkWrap2(b *testing.B) { benchmarkWrap(b, 2) }
func BenchmarkWrap5(b *testing.B) { benchmarkWrap(b, 5) }
func BenchmarkWrap10(b *testing.B) { benchmarkWrap(b, 10) }
func BenchmarkWrap25(b *testing.B) { benchmarkWrap(b, 25) }
func BenchmarkWrap80(b *testing.B) { benchmarkWrap(b, 80) }
func BenchmarkWrap120(b *testing.B) { benchmarkWrap(b, 120) }
func BenchmarkWrap500(b *testing.B) { benchmarkWrap(b, 500) }
func BenchmarkWrap1000(b *testing.B) { benchmarkWrap(b, 1000) }
func BenchmarkWrap5000(b *testing.B) { benchmarkWrap(b, 5000) }
func benchmarkWrapOptimal(b *testing.B, limit int) {
w := wrap.NewWrapper()
w.MinimumRaggedness = true
b.ReportAllocs()
for i := 0; i < b.N; i++ {
w.Wrap(loremIpsums[0], limit)
}
}
func BenchmarkWrapOptimal10(b *testing.B) { benchmarkWrapOptimal(b, 10) }
func BenchmarkWrapOptimal25(b *testing.B) { benchmarkWrapOptimal(b, 25) }
func BenchmarkWrapOptimal80(b *testing.B) { benchmarkWrapOptimal(b, 80) }
func BenchmarkWrapOptimal120(b *testing.B) { benchmarkWrapOptimal(b, 120) }
func BenchmarkWrapOptimal500(b *testing.B) { benchmarkWrapOptimal(b, 500) }
func BenchmarkWrapOptimal1000(b *testing.B) { benchmarkWrapOptimal(b, 1000) }
// BenchmarkGreedyVsOptimal compares greedy and optimal algorithms side by side.
func BenchmarkGreedyVsOptimal(b *testing.B) {
input := loremIpsums[0]
limit := 80
b.Run("Greedy", func(b *testing.B) {
w := wrap.NewWrapper()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
w.Wrap(input, limit)
}
})
b.Run("Optimal", func(b *testing.B) {
w := wrap.NewWrapper()
w.MinimumRaggedness = true
b.ReportAllocs()
for i := 0; i < b.N; i++ {
w.Wrap(input, limit)
}
})
}