-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiso_benchmark_test.go
More file actions
66 lines (58 loc) · 1.33 KB
/
iso_benchmark_test.go
File metadata and controls
66 lines (58 loc) · 1.33 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
package magicnumber_test
import (
"os"
"testing"
"github.com/Defacto2/magicnumber"
)
// BenchmarkISODetection measures the performance of ISO 9660 detection.
func BenchmarkISODetection(b *testing.B) {
f, err := os.Open(imgfile("uncompress.iso"))
if err != nil {
b.Fatal(err)
}
defer f.Close()
b.ResetTimer()
for b.Loop() {
// Reset file position for each iteration
_, err := f.Seek(0, 0)
if err != nil {
b.Fatal(err)
}
// Benchmark the ISO detection function
_ = magicnumber.ISO(f)
}
}
// BenchmarkISOFind measures the performance of ISO detection through the Find function.
func BenchmarkISOFind(b *testing.B) {
f, err := os.Open(imgfile("uncompress.iso"))
if err != nil {
b.Fatal(err)
}
defer f.Close()
b.ResetTimer()
for b.Loop() {
_, err := f.Seek(0, 0)
if err != nil {
b.Fatal(err)
}
// Benchmark detection through the general Find function
_ = magicnumber.Find(f)
}
}
// BenchmarkISODiscImage measures the performance of ISO detection through the DiscImage function.
func BenchmarkISODiscImage(b *testing.B) {
f, err := os.Open(imgfile("uncompress.iso"))
if err != nil {
b.Fatal(err)
}
defer f.Close()
b.ResetTimer()
for b.Loop() {
_, err := f.Seek(0, 0)
if err != nil {
b.Fatal(err)
}
// Benchmark detection through the DiscImage function
_, _ = magicnumber.DiscImage(f)
}
}