@@ -16,7 +16,7 @@ fn highlight_jquery_benchmark(c: &mut Criterion) {
1616
1717 c. bench_function ( "highlight jquery.js" , |b| {
1818 b. iter ( || {
19- registry. clear_pattern_cache ( ) ;
19+ registry. clear_caches ( ) ;
2020 let result = registry. highlight ( & jquery_content, & options) . unwrap ( ) ;
2121 std:: hint:: black_box ( result) ;
2222 } )
@@ -34,7 +34,7 @@ fn highlight_simple_benchmark(c: &mut Criterion) {
3434
3535 c. bench_function ( "highlight simple.ts" , |b| {
3636 b. iter ( || {
37- registry. clear_pattern_cache ( ) ;
37+ registry. clear_caches ( ) ;
3838 let result = registry. highlight ( & ts_content, & options) . unwrap ( ) ;
3939 std:: hint:: black_box ( result) ;
4040 } )
@@ -53,7 +53,7 @@ fn highlight_multiple_simple_benchmark(c: &mut Criterion) {
5353 c. bench_function ( "highlight multiple simple.ts" , |b| {
5454 b. iter ( || {
5555 // should not be 5x slower than "highlight simple.ts"
56- registry. clear_pattern_cache ( ) ;
56+ registry. clear_caches ( ) ;
5757 let result = registry. highlight ( & ts_content, & options) . unwrap ( ) ;
5858 std:: hint:: black_box ( result) ;
5959 let result = registry. highlight ( & ts_content, & options) . unwrap ( ) ;
@@ -81,7 +81,7 @@ fn highlight_sample_benchmark(c: &mut Criterion, grammar: &str) {
8181
8282 c. bench_function ( & format ! ( "highlight {grammar}.sample" ) , |b| {
8383 b. iter ( || {
84- registry. clear_pattern_cache ( ) ;
84+ registry. clear_caches ( ) ;
8585 let result = registry. highlight ( & content, & options) . unwrap ( ) ;
8686 std:: hint:: black_box ( result) ;
8787 } )
@@ -100,13 +100,75 @@ fn highlight_javascript_sample_benchmark(c: &mut Criterion) {
100100 highlight_sample_benchmark ( c, "javascript" ) ;
101101}
102102
103+ fn highlight_go_sample_benchmark ( c : & mut Criterion ) {
104+ highlight_sample_benchmark ( c, "go" ) ;
105+ }
106+
107+ fn highlight_ruby_sample_benchmark ( c : & mut Criterion ) {
108+ highlight_sample_benchmark ( c, "ruby" ) ;
109+ }
110+
111+ fn highlight_c_sample_benchmark ( c : & mut Criterion ) {
112+ highlight_sample_benchmark ( c, "c" ) ;
113+ }
114+
115+ fn highlight_html_sample_benchmark ( c : & mut Criterion ) {
116+ highlight_sample_benchmark ( c, "html" ) ;
117+ }
118+
119+ fn highlight_css_sample_benchmark ( c : & mut Criterion ) {
120+ highlight_sample_benchmark ( c, "css" ) ;
121+ }
122+
123+ fn highlight_python_sample_benchmark ( c : & mut Criterion ) {
124+ highlight_sample_benchmark ( c, "python" ) ;
125+ }
126+
127+ fn highlight_json_sample_benchmark ( c : & mut Criterion ) {
128+ highlight_sample_benchmark ( c, "json" ) ;
129+ }
130+
131+ fn highlight_tsx_sample_benchmark ( c : & mut Criterion ) {
132+ highlight_sample_benchmark ( c, "tsx" ) ;
133+ }
134+
135+ fn highlight_warm_benchmark ( c : & mut Criterion ) {
136+ let registry = Registry :: load_from_file ( "builtin.zst" ) . unwrap ( ) ;
137+ let mut group = c. benchmark_group ( "highlight warm" ) ;
138+ for ( grammar, path) in [
139+ ( "typescript" , "src/fixtures/samples/simple.ts" ) ,
140+ ( "javascript" , "src/fixtures/samples/jquery.js" ) ,
141+ ( "rust" , "grammars-themes/samples/rust.sample" ) ,
142+ ( "markdown" , "grammars-themes/samples/markdown.sample" ) ,
143+ ( "python" , "grammars-themes/samples/python.sample" ) ,
144+ ( "tsx" , "grammars-themes/samples/tsx.sample" ) ,
145+ ] {
146+ let content = fs:: read_to_string ( path) . unwrap ( ) ;
147+ let options = HighlightOptions :: new ( grammar, ThemeVariant :: Single ( "vitesse-black" ) ) ;
148+ registry. highlight ( & content, & options) . unwrap ( ) ;
149+ group. bench_function ( grammar, |b| {
150+ b. iter ( || std:: hint:: black_box ( registry. highlight ( & content, & options) . unwrap ( ) ) )
151+ } ) ;
152+ }
153+ group. finish ( ) ;
154+ }
155+
103156criterion_group ! (
104157 benches,
105158 highlight_jquery_benchmark,
106159 highlight_simple_benchmark,
107160 highlight_multiple_simple_benchmark,
108161 highlight_rust_sample_benchmark,
109162 highlight_markdown_sample_benchmark,
110- highlight_javascript_sample_benchmark
163+ highlight_javascript_sample_benchmark,
164+ highlight_go_sample_benchmark,
165+ highlight_ruby_sample_benchmark,
166+ highlight_c_sample_benchmark,
167+ highlight_html_sample_benchmark,
168+ highlight_css_sample_benchmark,
169+ highlight_python_sample_benchmark,
170+ highlight_json_sample_benchmark,
171+ highlight_tsx_sample_benchmark,
172+ highlight_warm_benchmark
111173) ;
112174criterion_main ! ( benches) ;
0 commit comments