File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 1+ use criterion:: { criterion_group, criterion_main, Criterion } ;
2+ use pyo3:: types:: PyString ;
3+ use pyo3:: Python ;
4+ use std:: hint:: black_box;
5+
6+ fn bench_pystring_from_fmt ( c : & mut Criterion ) {
7+ Python :: attach ( |py| {
8+ c. bench_function ( "PyString::from_fmt simple" , |b| {
9+ b. iter ( || {
10+ let format_args = format_args ! ( "Hello {}!" , "world" ) ;
11+ let s = Ok ( PyString :: new ( py, & format ! ( "{format_args}" ) ) ) ;
12+ assert ! ( s. is_ok( ) ) ;
13+ } )
14+ } ) ;
15+ c. bench_function ( "PyString::from_fmt complex" , |b| {
16+ b. iter ( || {
17+ let value = ( black_box ( 42 ) , black_box ( "foo" ) , [ 0 ; 0 ] ) ;
18+ let format_args = format_args ! ( "This is some complex value: {value:?}" ) ;
19+ let s = Ok ( PyString :: new ( py, & format ! ( "{format_args}" ) ) ) ;
20+ assert ! ( s. is_ok( ) ) ;
21+ } )
22+ } ) ;
23+ } ) ;
24+ }
25+
26+ criterion_group ! ( benches, bench_pystring_from_fmt) ;
27+ criterion_main ! ( benches) ;
You can’t perform that action at this time.
0 commit comments