1515// specific language governing permissions and limitations
1616// under the License.
1717
18- use std:: sync:: Arc ;
1918use arrow:: array:: { BooleanBuilder , RecordBatch } ;
2019use arrow:: datatypes:: { DataType , Field , Schema } ;
2120use criterion:: { criterion_group, criterion_main, Criterion } ;
2221use datafusion:: physical_expr:: expressions:: Column ;
2322use datafusion:: physical_expr:: PhysicalExpr ;
2423use datafusion_comet_spark_expr:: { Cast , EvalMode , SparkCastOptions } ;
24+ use std:: sync:: Arc ;
2525
2626fn criterion_benchmark ( c : & mut Criterion ) {
2727 let expr = Arc :: new ( Column :: new ( "a" , 0 ) ) ;
2828 let boolean_batch = create_boolean_batch ( ) ;
2929 let spark_cast_options = SparkCastOptions :: new ( EvalMode :: Legacy , "UTC" , false ) ;
3030 Cast :: new ( expr. clone ( ) , DataType :: Int8 , spark_cast_options. clone ( ) ) ;
31- let cast_to_i8 = Cast :: new ( expr. clone ( ) , DataType :: Boolean , spark_cast_options. clone ( ) ) ;
32- let cast_to_i16 = Cast :: new ( expr. clone ( ) , DataType :: Boolean , spark_cast_options. clone ( ) ) ;
33- let cast_to_i32 = Cast :: new ( expr. clone ( ) , DataType :: Boolean , spark_cast_options. clone ( ) ) ;
34- let cast_to_i64 = Cast :: new ( expr. clone ( ) , DataType :: Boolean , spark_cast_options) ;
31+ let cast_to_i8 = Cast :: new ( expr. clone ( ) , DataType :: Int8 , spark_cast_options. clone ( ) ) ;
32+ let cast_to_i16 = Cast :: new ( expr. clone ( ) , DataType :: Int16 , spark_cast_options. clone ( ) ) ;
33+ let cast_to_i32 = Cast :: new ( expr. clone ( ) , DataType :: Int32 , spark_cast_options. clone ( ) ) ;
34+ let cast_to_i64 = Cast :: new ( expr. clone ( ) , DataType :: Int64 , spark_cast_options. clone ( ) ) ;
35+ let cast_to_f32 = Cast :: new ( expr. clone ( ) , DataType :: Float32 , spark_cast_options. clone ( ) ) ;
36+ let cast_to_f64 = Cast :: new ( expr. clone ( ) , DataType :: Float64 , spark_cast_options. clone ( ) ) ;
37+ let cast_to_str = Cast :: new ( expr, DataType :: Utf8 , spark_cast_options) ;
3538
3639 let mut group = c. benchmark_group ( format ! ( "cast_bool_to_int" ) ) ;
3740 group. bench_function ( "i8" , |b| {
@@ -46,6 +49,15 @@ fn criterion_benchmark(c: &mut Criterion) {
4649 group. bench_function ( "i64" , |b| {
4750 b. iter ( || cast_to_i64. evaluate ( & boolean_batch) . unwrap ( ) ) ;
4851 } ) ;
52+ group. bench_function ( "f32" , |b| {
53+ b. iter ( || cast_to_f32. evaluate ( & boolean_batch) . unwrap ( ) ) ;
54+ } ) ;
55+ group. bench_function ( "f64" , |b| {
56+ b. iter ( || cast_to_f64. evaluate ( & boolean_batch) . unwrap ( ) ) ;
57+ } ) ;
58+ group. bench_function ( "str" , |b| {
59+ b. iter ( || cast_to_str. evaluate ( & boolean_batch) . unwrap ( ) ) ;
60+ } ) ;
4961}
5062
5163fn create_boolean_batch ( ) -> RecordBatch {
@@ -71,4 +83,4 @@ criterion_group! {
7183 config = config( ) ;
7284 targets = criterion_benchmark
7385}
74- criterion_main ! ( benches) ;
86+ criterion_main ! ( benches) ;
0 commit comments