File tree Expand file tree Collapse file tree 6 files changed +82
-2
lines changed Expand file tree Collapse file tree 6 files changed +82
-2
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ permissions:
13
13
jobs :
14
14
benchmark :
15
15
name : Run Benchmarks
16
- runs-on : macos-14
16
+ runs-on : ubuntu-latest
17
17
permissions :
18
18
pull-requests : write
19
19
steps :
29
29
- name : Install benchmarking tools
30
30
uses : bencherdev/bencher@main
31
31
32
+ - name : Install crate dependencies
33
+ run : sudo apt-get install libmagic1 libmagic-dev
34
+
32
35
- name : Run benchmarks
33
36
if : ${{ github.event_name == 'pull_request' }}
34
37
env :
Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ csv = "1.3.1"
36
36
file-format = " 0.26.0"
37
37
infer = " 0.19.0"
38
38
indoc = " 2.0.5"
39
+ magic = " 0.16.2"
39
40
mime_guess = " 2.0.5"
40
41
quick-xml = " 0.37.2"
41
42
rayon = " 1.5.1"
Original file line number Diff line number Diff line change @@ -110,9 +110,10 @@ Data is licensed under the following licenses:
110
110
111
111
If this crate does not meet your requirements, you may want to consider the following alternatives:
112
112
113
+ * [ file-format] ( https://crates.io/crates/file-format )
113
114
* [ infer] ( https://crates.io/crates/infer )
115
+ * [ magic] ( https://crates.io/crates/magic )
114
116
* [ mime_guess] ( https://crates.io/crates/mime_guess )
115
- * [ file-format] ( https://crates.io/crates/file-format )
116
117
117
118
## Contribution
118
119
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ anyhow = { workspace = true }
23
23
criterion = { workspace = true }
24
24
file-format = { workspace = true }
25
25
infer = { workspace = true }
26
+ magic = { workspace = true }
26
27
mime_guess = { workspace = true }
27
28
tokio = { workspace = true , features = [" full" ] }
28
29
Original file line number Diff line number Diff line change @@ -102,6 +102,37 @@ fn bench_lifecycle(criterion: &mut Criterion) -> anyhow::Result<()> {
102
102
} ) ;
103
103
} ) ;
104
104
105
+ //
106
+ // Comparison testing to the magic crate
107
+ //
108
+ #[ cfg( target_os = "linux" ) ]
109
+ {
110
+ let cookie = magic:: Cookie :: open ( Default :: default ( ) ) ?;
111
+ let cookie = cookie
112
+ . load ( & Default :: default ( ) )
113
+ . expect ( "failed to load magic database" ) ;
114
+
115
+ criterion. bench_function ( "magic::from_bytes" , |bencher| {
116
+ bencher. iter ( || {
117
+ // human-readable description, more than a static name
118
+ cookie. set_flags ( magic:: cookie:: Flags :: ERROR ) . unwrap ( ) ;
119
+ let _ = cookie. buffer ( & bytes) . unwrap ( ) ;
120
+
121
+ // file type extensions
122
+ cookie
123
+ . set_flags ( magic:: cookie:: Flags :: ERROR | magic:: cookie:: Flags :: EXTENSION )
124
+ . unwrap ( ) ;
125
+ let _ = cookie. buffer ( & bytes) . unwrap ( ) ;
126
+
127
+ // media type
128
+ cookie
129
+ . set_flags ( magic:: cookie:: Flags :: ERROR | magic:: cookie:: Flags :: MIME_TYPE )
130
+ . unwrap ( ) ;
131
+ let _ = cookie. buffer ( & bytes) . unwrap ( ) ;
132
+ } ) ;
133
+ } ) ;
134
+ }
135
+
105
136
//
106
137
// Comparison testing to the mime_guess crate
107
138
//
You can’t perform that action at this time.
0 commit comments