@@ -9,39 +9,55 @@ fn main() {
99
1010#[ divan:: bench( args = template_fixtures( ) ) ]
1111fn parse_template ( bencher : Bencher , fixture : & TemplateFixture ) {
12- let mut db = Db :: new ( ) ;
13-
14- let mut revision: u64 = 1 ;
15- bencher. bench_local ( move || {
16- let path = format ! ( "{}.bench{}" , fixture. path. clone( ) , revision) ;
17- let file = db. file_with_contents ( path. into ( ) , & fixture. source ) ;
18-
19- if let Some ( nodelist) = djls_templates:: parse_template ( & db, file) {
20- divan:: black_box ( nodelist. nodelist ( & db) . len ( ) ) ;
21- }
22-
23- revision = revision. wrapping_add ( 1 ) ;
24- } ) ;
12+ let db = std:: cell:: RefCell :: new ( Db :: new ( ) ) ;
13+
14+ let counter = std:: cell:: Cell :: new ( 0_usize ) ;
15+
16+ bencher
17+ . with_inputs ( || {
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 ( ) )
23+ } )
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 ( ) ) ;
28+ }
29+ } ) ;
2530}
2631
2732#[ divan:: bench]
2833fn parse_all_templates ( bencher : Bencher ) {
2934 let fixtures = template_fixtures ( ) ;
30- let mut db = Db :: new ( ) ;
31-
32- let mut revision: u64 = 1 ;
33- bencher. bench_local ( move || {
34- for fixture in fixtures {
35- let path = format ! ( "{}.bench{}" , fixture. path, revision) ;
36- let file = db. file_with_contents ( path. into ( ) , & fixture. source ) ;
37-
38- if let Some ( nodelist) = djls_templates:: parse_template ( & db, file) {
39- divan:: black_box ( nodelist. nodelist ( & db) . len ( ) ) ;
35+ let db = std:: cell:: RefCell :: new ( Db :: new ( ) ) ;
36+
37+ let counter = std:: cell:: Cell :: new ( 0_usize ) ;
38+
39+ bencher
40+ . with_inputs ( || {
41+ let i = counter. get ( ) ;
42+ counter. set ( i + 1 ) ;
43+
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 < _ > > ( )
52+ } )
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 ( ) ) ;
58+ }
4059 }
41- }
42-
43- revision = revision. wrapping_add ( 1 ) ;
44- } ) ;
60+ } ) ;
4561}
4662
4763#[ divan:: bench( args = template_fixtures( ) ) ]
0 commit comments