@@ -9,43 +9,54 @@ fn main() {
99
1010#[ divan:: bench( args = template_fixtures( ) ) ]
1111fn parse_template ( bencher : Bencher , fixture : & TemplateFixture ) {
12+ let db = std:: cell:: RefCell :: new ( Db :: new ( ) ) ;
13+
14+ let counter = std:: cell:: Cell :: new ( 0_usize ) ;
15+
1216 bencher
1317 . with_inputs ( || {
14- let mut db = Db :: new ( ) ;
15- let file = db. file_with_contents ( fixture. path . clone ( ) , & fixture. source ) ;
16- ( db, file)
18+ let i = counter. get ( ) ;
19+ counter. set ( i + 1 ) ;
20+ let path = format ! ( "{}.bench{}" , fixture. path. clone( ) , i) ;
21+ db. borrow_mut ( )
22+ . file_with_contents ( path. into ( ) , & fixture. source . clone ( ) )
1723 } )
18- . bench_local_values ( |( db, file) | {
19- if let Some ( nodelist) = djls_templates:: parse_template ( & db, file) {
20- divan:: black_box ( nodelist. nodelist ( & db) . len ( ) ) ;
24+ . bench_local_values ( |file| {
25+ let db = db. borrow ( ) ;
26+ if let Some ( nodelist) = djls_templates:: parse_template ( & * db, file) {
27+ divan:: black_box ( nodelist. nodelist ( & * db) . len ( ) ) ;
2128 }
22- ( db, file)
2329 } ) ;
2430}
2531
2632#[ divan:: bench]
2733fn parse_all_templates ( bencher : Bencher ) {
2834 let fixtures = template_fixtures ( ) ;
35+ let db = std:: cell:: RefCell :: new ( Db :: new ( ) ) ;
36+
37+ let counter = std:: cell:: Cell :: new ( 0_usize ) ;
2938
3039 bencher
3140 . with_inputs ( || {
32- let mut db = Db :: new ( ) ;
33- let mut files = Vec :: with_capacity ( fixtures. len ( ) ) ;
34-
35- for fixture in fixtures {
36- let file = db. file_with_contents ( fixture. path . clone ( ) , & fixture. source ) ;
37- files. push ( file) ;
38- }
41+ let i = counter. get ( ) ;
42+ counter. set ( i + 1 ) ;
3943
40- ( db, files)
44+ let mut db = db. borrow_mut ( ) ;
45+ fixtures
46+ . iter ( )
47+ . map ( |fixture| {
48+ let path = format ! ( "{}.bench{}" , fixture. path, i) ;
49+ db. file_with_contents ( path. into ( ) , & fixture. source )
50+ } )
51+ . collect :: < Vec < _ > > ( )
4152 } )
42- . bench_local_values ( |( db, files) | {
43- for file in & files {
44- if let Some ( nodelist) = djls_templates:: parse_template ( & db, * file) {
45- divan:: black_box ( nodelist. nodelist ( & db) . len ( ) ) ;
53+ . bench_local_values ( |files| {
54+ let db = db. borrow ( ) ;
55+ for file in files {
56+ if let Some ( nodelist) = djls_templates:: parse_template ( & * db, file) {
57+ divan:: black_box ( nodelist. nodelist ( & * db) . len ( ) ) ;
4658 }
4759 }
48- ( db, files)
4960 } ) ;
5061}
5162
0 commit comments