Debian Codegraph @

bench/bench_test.go

raw symbols SCIP
1 package bench
2
3 import (
4 "os"
5 "os/exec"
6 "testing"
7
8 "github.com/containerd/continuity"
9 "github.com/docker/docker/pkg/archive"
10 "github.com/docker/docker/pkg/reexec"
11 )
12
13 func init() {
14 reexec.Init()
15 }
16
17 func benchmarkInitialCopy(b *testing.B, fn func(string, string) error, size int) {
18 baseDir := os.Getenv("BENCH_BASE_DIR")
19 verify := os.Getenv("BENCH_VERIFY") == "1"
20 for i := 0; i < b.N; i++ {
21 b.StopTimer()
22 tmpdir, err := createTestDir(size)
23 if err != nil {
24 b.Error(err)
25 }
26 destdir, err := os.MkdirTemp(baseDir, "destdir")
27 if err != nil {
28 os.RemoveAll(tmpdir)
29 b.Error(err)
30 }
31
32 var m *continuity.Manifest
33 if verify {
34 ctx, err := continuity.NewContext(tmpdir)
35 if err != nil {
36 b.Error(err)
37 }
38 m, err = continuity.BuildManifest(ctx)
39 if err != nil {
40 b.Error(err)
41 }
42 }
43 b.StartTimer()
44 err = fn(tmpdir, destdir)
45 if err != nil {
46 b.Error(err)
47 }
48 b.StopTimer()
49 if verify {
50 ctx2, err := continuity.NewContext(destdir)
51 if err != nil {
52 b.Fatal(err)
53 }
54 err = continuity.VerifyManifest(ctx2, m)
55 if err != nil {
56 b.Error(err)
57 }
58 }
59 os.RemoveAll(tmpdir)
60 os.RemoveAll(destdir)
61 }
62 }
63
64 func benchmarkIncrementalCopy(b *testing.B, fn func(string, string) error, size int) {
65 b.StopTimer()
66 baseDir := os.Getenv("BENCH_BASE_DIR")
67 verify := os.Getenv("BENCH_VERIFY") == "1"
68 tmpdir, err := createTestDir(size)
69 if err != nil {
70 b.Error(err)
71 }
72 destdir, err := os.MkdirTemp(baseDir, "destdir")
73 if err != nil {
74 os.RemoveAll(tmpdir)
75 b.Error(err)
76 }
77 err = fn(tmpdir, destdir)
78 if err != nil {
79 b.Error(err)
80 }
81 defer os.RemoveAll(tmpdir)
82 defer os.RemoveAll(destdir)
83 for i := 0; i < b.N; i++ {
84 if err := mutate(tmpdir, 2); err != nil {
85 b.Error(err)
86 }
87 var m *continuity.Manifest
88 if verify {
89 ctx, err := continuity.NewContext(tmpdir)
90 if err != nil {
91 b.Error(err)
92 }
93 m, err = continuity.BuildManifest(ctx)
94 if err != nil {
95 b.Error(err)
96 }
97 }
98 b.StartTimer()
99 err = fn(tmpdir, destdir)
100 if err != nil {
101 b.Error(err)
102 }
103 b.StopTimer()
104 if verify {
105 ctx2, err := continuity.NewContext(destdir)
106 if err != nil {
107 b.Fatal(err)
108 }
109 err = continuity.VerifyManifest(ctx2, m)
110 if err != nil {
111 b.Error(err)
112 }
113 }
114 }
115 }
116
117 func copyWithTar(src, dest string) error {
118 return archive.NewDefaultArchiver().CopyWithTar(src, dest)
119 }
120
121 func cpa(src, dest string) error {
122 cmd := exec.Command("cp", "-a", src+"/.", dest)
123 return cmd.Run()
124 }
125
126 func rsync(src, dest string) error {
127 cmd := exec.Command("rsync", "-a", "--del", src+"/.", dest)
128 return cmd.Run()
129 }
130
131 func gnutar(src, dest string) error {
132 tar := exec.Command("tar", "-cf", "-", "-C", src, ".")
133 unpack := exec.Command("tar", "xf", "-", "-C", dest)
134 stdout, err := tar.StdoutPipe()
135 if err != nil {
136 return err
137 }
138 unpack.Stdin = stdout
139 go tar.Run()
140 return unpack.Run()
141 }
142
143 func BenchmarkCopyWithTar10(b *testing.B) {
144 benchmarkInitialCopy(b, copyWithTar, 10)
145 }
146
147 func BenchmarkCopyWithTar50(b *testing.B) {
148 benchmarkInitialCopy(b, copyWithTar, 50)
149 }
150
151 func BenchmarkCopyWithTar200(b *testing.B) {
152 benchmarkInitialCopy(b, copyWithTar, 200)
153 }
154
155 func BenchmarkCopyWithTar1000(b *testing.B) {
156 benchmarkInitialCopy(b, copyWithTar, 1000)
157 }
158
159 // func chrootCopyWithTar(src, dest string) error {
160 // return chrootarchive.NewArchiver(nil).CopyWithTar(src, dest)
161 // }
162 // func BenchmarkChrootCopyWithTar10(b *testing.B) {
163 // benchmarkInitialCopy(b, chrootCopyWithTar, 10)
164 // }
165 //
166 // func BenchmarkChrootCopyWithTar50(b *testing.B) {
167 // benchmarkInitialCopy(b, chrootCopyWithTar, 50)
168 // }
169 //
170 // func BenchmarkChrootCopyWithTar200(b *testing.B) {
171 // benchmarkInitialCopy(b, chrootCopyWithTar, 200)
172 // }
173 //
174 // func BenchmarkChrootCopyWithTar1000(b *testing.B) {
175 // benchmarkInitialCopy(b, chrootCopyWithTar, 1000)
176 // }
177
178 func BenchmarkCPA10(b *testing.B) {
179 benchmarkInitialCopy(b, cpa, 10)
180 }
181
182 func BenchmarkCPA50(b *testing.B) {
183 benchmarkInitialCopy(b, cpa, 50)
184 }
185
186 func BenchmarkCPA200(b *testing.B) {
187 benchmarkInitialCopy(b, cpa, 200)
188 }
189
190 func BenchmarkCPA1000(b *testing.B) {
191 benchmarkInitialCopy(b, cpa, 1000)
192 }
193
194 func BenchmarkDiffCopy10(b *testing.B) {
195 benchmarkInitialCopy(b, diffCopyReg, 10)
196 }
197
198 func BenchmarkDiffCopy50(b *testing.B) {
199 benchmarkInitialCopy(b, diffCopyReg, 50)
200 }
201
202 func BenchmarkDiffCopy200(b *testing.B) {
203 benchmarkInitialCopy(b, diffCopyReg, 200)
204 }
205
206 func BenchmarkDiffCopy1000(b *testing.B) {
207 benchmarkInitialCopy(b, diffCopyReg, 1000)
208 }
209
210 func BenchmarkDiffCopyProto10(b *testing.B) {
211 benchmarkInitialCopy(b, diffCopyProto, 10)
212 }
213
214 func BenchmarkDiffCopyProto50(b *testing.B) {
215 benchmarkInitialCopy(b, diffCopyProto, 50)
216 }
217
218 func BenchmarkDiffCopyProto200(b *testing.B) {
219 benchmarkInitialCopy(b, diffCopyProto, 200)
220 }
221
222 func BenchmarkDiffCopyProto1000(b *testing.B) {
223 benchmarkInitialCopy(b, diffCopyProto, 1000)
224 }
225
226 func BenchmarkIncrementalDiffCopy10(b *testing.B) {
227 benchmarkIncrementalCopy(b, diffCopyReg, 10)
228 }
229 func BenchmarkIncrementalDiffCopy50(b *testing.B) {
230 benchmarkIncrementalCopy(b, diffCopyReg, 50)
231 }
232 func BenchmarkIncrementalDiffCopy200(b *testing.B) {
233 benchmarkIncrementalCopy(b, diffCopyReg, 200)
234 }
235 func BenchmarkIncrementalDiffCopy1000(b *testing.B) {
236 benchmarkIncrementalCopy(b, diffCopyReg, 1000)
237 }
238
239 func BenchmarkIncrementalDiffCopy5000(b *testing.B) {
240 benchmarkIncrementalCopy(b, diffCopyReg, 5000)
241 }
242 func BenchmarkIncrementalDiffCopy10000(b *testing.B) {
243 benchmarkIncrementalCopy(b, diffCopyReg, 10000)
244 }
245
246 func BenchmarkIncrementalCopyWithTar10(b *testing.B) {
247 benchmarkIncrementalCopy(b, copyWithTar, 10)
248 }
249 func BenchmarkIncrementalCopyWithTar50(b *testing.B) {
250 benchmarkIncrementalCopy(b, copyWithTar, 50)
251 }
252 func BenchmarkIncrementalCopyWithTar200(b *testing.B) {
253 benchmarkIncrementalCopy(b, copyWithTar, 200)
254 }
255 func BenchmarkIncrementalCopyWithTar1000(b *testing.B) {
256 benchmarkIncrementalCopy(b, copyWithTar, 1000)
257 }
258
259 func BenchmarkIncrementalRsync10(b *testing.B) {
260 benchmarkIncrementalCopy(b, rsync, 10)
261 }
262 func BenchmarkIncrementalRsync50(b *testing.B) {
263 benchmarkIncrementalCopy(b, rsync, 50)
264 }
265 func BenchmarkIncrementalRsync200(b *testing.B) {
266 benchmarkIncrementalCopy(b, rsync, 200)
267 }
268 func BenchmarkIncrementalRsync1000(b *testing.B) {
269 benchmarkIncrementalCopy(b, rsync, 1000)
270 }
271
272 func BenchmarkIncrementalRsync5000(b *testing.B) {
273 benchmarkIncrementalCopy(b, rsync, 5000)
274 }
275 func BenchmarkIncrementalRsync10000(b *testing.B) {
276 benchmarkIncrementalCopy(b, rsync, 10000)
277 }
278
279 func BenchmarkRsync10(b *testing.B) {
280 benchmarkInitialCopy(b, rsync, 10)
281 }
282
283 func BenchmarkRsync50(b *testing.B) {
284 benchmarkInitialCopy(b, rsync, 50)
285 }
286
287 func BenchmarkRsync200(b *testing.B) {
288 benchmarkInitialCopy(b, rsync, 200)
289 }
290
291 func BenchmarkRsync1000(b *testing.B) {
292 benchmarkInitialCopy(b, rsync, 1000)
293 }
294
295 func BenchmarkGnuTar10(b *testing.B) {
296 benchmarkInitialCopy(b, gnutar, 10)
297 }
298
299 func BenchmarkGnuTar50(b *testing.B) {
300 benchmarkInitialCopy(b, gnutar, 50)
301 }
302
303 func BenchmarkGnuTar200(b *testing.B) {
304 benchmarkInitialCopy(b, gnutar, 200)
305 }
306
307 func BenchmarkGnuTar1000(b *testing.B) {
308 benchmarkInitialCopy(b, gnutar, 1000)
309 }