File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -170,6 +170,22 @@ fn bench_parse_strftime_localized(c: &mut Criterion) {
170170 } ) ;
171171}
172172
173+ fn bench_format_to_string ( c : & mut Criterion ) {
174+ let dt = Local :: now ( ) ;
175+ c. bench_function ( "bench_format_to_string" , |b| {
176+ b. iter ( || black_box ( dt) . format_to_string ( "%Y-%m-%dT%H:%M:%S%.f%:z" ) )
177+ } ) ;
178+ }
179+
180+ fn bench_format_with ( c : & mut Criterion ) {
181+ let dt = Local :: now ( ) ;
182+ let fmt_items: Vec < _ > = StrftimeItems :: new ( "%Y-%m-%dT%H:%M:%S%.f%:z" ) . collect ( ) ;
183+ let formatter = DateTime :: formatter ( & fmt_items) . unwrap ( ) ;
184+ c. bench_function ( "bench_format_with" , |b| {
185+ b. iter ( || format ! ( "{}" , black_box( dt) . format_with( & formatter) ) )
186+ } ) ;
187+ }
188+
173189fn bench_format ( c : & mut Criterion ) {
174190 let dt = Local :: now ( ) ;
175191 c. bench_function ( "bench_format" , |b| {
@@ -235,6 +251,8 @@ criterion_group!(
235251 bench_get_local_time,
236252 bench_parse_strftime,
237253 bench_format,
254+ bench_format_to_string,
255+ bench_format_with,
238256 bench_format_with_items,
239257 bench_format_manual,
240258 bench_naivedate_add_signed,
You can’t perform that action at this time.
0 commit comments