|
17 | 17 |
|
18 | 18 | extern crate criterion; |
19 | 19 |
|
| 20 | +use std::sync::Arc; |
| 21 | + |
| 22 | +use arrow_array::builder::StringBuilder; |
| 23 | +use arrow_array::ArrayRef; |
20 | 24 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; |
21 | 25 |
|
22 | | -use datafusion_expr::lit; |
23 | | -use datafusion_functions::expr_fn::to_timestamp; |
| 26 | +use datafusion_expr::ColumnarValue; |
| 27 | +use datafusion_functions::datetime::to_timestamp; |
24 | 28 |
|
25 | 29 | fn criterion_benchmark(c: &mut Criterion) { |
26 | 30 | c.bench_function("to_timestamp_no_formats", |b| { |
27 | | - let inputs = vec![ |
28 | | - lit("1997-01-31T09:26:56.123Z"), |
29 | | - lit("1997-01-31T09:26:56.123-05:00"), |
30 | | - lit("1997-01-31 09:26:56.123-05:00"), |
31 | | - lit("2023-01-01 04:05:06.789 -08"), |
32 | | - lit("1997-01-31T09:26:56.123"), |
33 | | - lit("1997-01-31 09:26:56.123"), |
34 | | - lit("1997-01-31 09:26:56"), |
35 | | - lit("1997-01-31 13:26:56"), |
36 | | - lit("1997-01-31 13:26:56+04:00"), |
37 | | - lit("1997-01-31"), |
38 | | - ]; |
| 31 | + let mut inputs = StringBuilder::new(); |
| 32 | + inputs.append_value("1997-01-31T09:26:56.123Z"); |
| 33 | + inputs.append_value("1997-01-31T09:26:56.123-05:00"); |
| 34 | + inputs.append_value("1997-01-31 09:26:56.123-05:00"); |
| 35 | + inputs.append_value("2023-01-01 04:05:06.789 -08"); |
| 36 | + inputs.append_value("1997-01-31T09:26:56.123"); |
| 37 | + inputs.append_value("1997-01-31 09:26:56.123"); |
| 38 | + inputs.append_value("1997-01-31 09:26:56"); |
| 39 | + inputs.append_value("1997-01-31 13:26:56"); |
| 40 | + inputs.append_value("1997-01-31 13:26:56+04:00"); |
| 41 | + inputs.append_value("1997-01-31"); |
| 42 | + |
| 43 | + let string_array = ColumnarValue::Array(Arc::new(inputs.finish()) as ArrayRef); |
| 44 | + |
39 | 45 | b.iter(|| { |
40 | | - for i in inputs.iter() { |
41 | | - black_box(to_timestamp(vec![i.clone()])); |
42 | | - } |
43 | | - }); |
| 46 | + black_box( |
| 47 | + to_timestamp() |
| 48 | + .invoke(&[string_array.clone()]) |
| 49 | + .expect("to_timestamp should work on valid values"), |
| 50 | + ) |
| 51 | + }) |
44 | 52 | }); |
45 | 53 |
|
46 | 54 | c.bench_function("to_timestamp_with_formats", |b| { |
47 | | - let mut inputs = vec![]; |
48 | | - let mut format1 = vec![]; |
49 | | - let mut format2 = vec![]; |
50 | | - let mut format3 = vec![]; |
51 | | - |
52 | | - inputs.push(lit("1997-01-31T09:26:56.123Z")); |
53 | | - format1.push(lit("%+")); |
54 | | - format2.push(lit("%c")); |
55 | | - format3.push(lit("%Y-%m-%dT%H:%M:%S%.f%Z")); |
56 | | - |
57 | | - inputs.push(lit("1997-01-31T09:26:56.123-05:00")); |
58 | | - format1.push(lit("%+")); |
59 | | - format2.push(lit("%c")); |
60 | | - format3.push(lit("%Y-%m-%dT%H:%M:%S%.f%z")); |
61 | | - |
62 | | - inputs.push(lit("1997-01-31 09:26:56.123-05:00")); |
63 | | - format1.push(lit("%+")); |
64 | | - format2.push(lit("%c")); |
65 | | - format3.push(lit("%Y-%m-%d %H:%M:%S%.f%Z")); |
66 | | - |
67 | | - inputs.push(lit("2023-01-01 04:05:06.789 -08")); |
68 | | - format1.push(lit("%+")); |
69 | | - format2.push(lit("%c")); |
70 | | - format3.push(lit("%Y-%m-%d %H:%M:%S%.f %#z")); |
71 | | - |
72 | | - inputs.push(lit("1997-01-31T09:26:56.123")); |
73 | | - format1.push(lit("%+")); |
74 | | - format2.push(lit("%c")); |
75 | | - format3.push(lit("%Y-%m-%dT%H:%M:%S%.f")); |
76 | | - |
77 | | - inputs.push(lit("1997-01-31 09:26:56.123")); |
78 | | - format1.push(lit("%+")); |
79 | | - format2.push(lit("%c")); |
80 | | - format3.push(lit("%Y-%m-%d %H:%M:%S%.f")); |
81 | | - |
82 | | - inputs.push(lit("1997-01-31 09:26:56")); |
83 | | - format1.push(lit("%+")); |
84 | | - format2.push(lit("%c")); |
85 | | - format3.push(lit("%Y-%m-%d %H:%M:%S")); |
86 | | - |
87 | | - inputs.push(lit("1997-01-31 092656")); |
88 | | - format1.push(lit("%+")); |
89 | | - format2.push(lit("%c")); |
90 | | - format3.push(lit("%Y-%m-%d %H%M%S")); |
91 | | - |
92 | | - inputs.push(lit("1997-01-31 092656+04:00")); |
93 | | - format1.push(lit("%+")); |
94 | | - format2.push(lit("%c")); |
95 | | - format3.push(lit("%Y-%m-%d %H%M%S%:z")); |
96 | | - |
97 | | - inputs.push(lit("Sun Jul 8 00:34:60 2001")); |
98 | | - format1.push(lit("%+")); |
99 | | - format2.push(lit("%c")); |
100 | | - format3.push(lit("%Y-%m-%d 00:00:00")); |
101 | | - |
| 55 | + let mut inputs = StringBuilder::new(); |
| 56 | + let mut format1_builder = StringBuilder::with_capacity(2, 10); |
| 57 | + let mut format2_builder = StringBuilder::with_capacity(2, 10); |
| 58 | + let mut format3_builder = StringBuilder::with_capacity(2, 10); |
| 59 | + |
| 60 | + inputs.append_value("1997-01-31T09:26:56.123Z"); |
| 61 | + format1_builder.append_value("%+"); |
| 62 | + format2_builder.append_value("%c"); |
| 63 | + format3_builder.append_value("%Y-%m-%dT%H:%M:%S%.f%Z"); |
| 64 | + |
| 65 | + inputs.append_value("1997-01-31T09:26:56.123-05:00"); |
| 66 | + format1_builder.append_value("%+"); |
| 67 | + format2_builder.append_value("%c"); |
| 68 | + format3_builder.append_value("%Y-%m-%dT%H:%M:%S%.f%z"); |
| 69 | + |
| 70 | + inputs.append_value("1997-01-31 09:26:56.123-05:00"); |
| 71 | + format1_builder.append_value("%+"); |
| 72 | + format2_builder.append_value("%c"); |
| 73 | + format3_builder.append_value("%Y-%m-%d %H:%M:%S%.f%Z"); |
| 74 | + |
| 75 | + inputs.append_value("2023-01-01 04:05:06.789 -08"); |
| 76 | + format1_builder.append_value("%+"); |
| 77 | + format2_builder.append_value("%c"); |
| 78 | + format3_builder.append_value("%Y-%m-%d %H:%M:%S%.f %#z"); |
| 79 | + |
| 80 | + inputs.append_value("1997-01-31T09:26:56.123"); |
| 81 | + format1_builder.append_value("%+"); |
| 82 | + format2_builder.append_value("%c"); |
| 83 | + format3_builder.append_value("%Y-%m-%dT%H:%M:%S%.f"); |
| 84 | + |
| 85 | + inputs.append_value("1997-01-31 09:26:56.123"); |
| 86 | + format1_builder.append_value("%+"); |
| 87 | + format2_builder.append_value("%c"); |
| 88 | + format3_builder.append_value("%Y-%m-%d %H:%M:%S%.f"); |
| 89 | + |
| 90 | + inputs.append_value("1997-01-31 09:26:56"); |
| 91 | + format1_builder.append_value("%+"); |
| 92 | + format2_builder.append_value("%c"); |
| 93 | + format3_builder.append_value("%Y-%m-%d %H:%M:%S"); |
| 94 | + |
| 95 | + inputs.append_value("1997-01-31 092656"); |
| 96 | + format1_builder.append_value("%+"); |
| 97 | + format2_builder.append_value("%c"); |
| 98 | + format3_builder.append_value("%Y-%m-%d %H%M%S"); |
| 99 | + |
| 100 | + inputs.append_value("1997-01-31 092656+04:00"); |
| 101 | + format1_builder.append_value("%+"); |
| 102 | + format2_builder.append_value("%c"); |
| 103 | + format3_builder.append_value("%Y-%m-%d %H%M%S%:z"); |
| 104 | + |
| 105 | + inputs.append_value("Sun Jul 8 00:34:60 2001"); |
| 106 | + format1_builder.append_value("%+"); |
| 107 | + format2_builder.append_value("%c"); |
| 108 | + format3_builder.append_value("%Y-%m-%d 00:00:00"); |
| 109 | + |
| 110 | + let args = [ |
| 111 | + ColumnarValue::Array(Arc::new(inputs.finish()) as ArrayRef), |
| 112 | + ColumnarValue::Array(Arc::new(format1_builder.finish()) as ArrayRef), |
| 113 | + ColumnarValue::Array(Arc::new(format2_builder.finish()) as ArrayRef), |
| 114 | + ColumnarValue::Array(Arc::new(format3_builder.finish()) as ArrayRef), |
| 115 | + ]; |
102 | 116 | b.iter(|| { |
103 | | - inputs.iter().enumerate().for_each(|(idx, i)| { |
104 | | - black_box(to_timestamp(vec![ |
105 | | - i.clone(), |
106 | | - format1.get(idx).unwrap().clone(), |
107 | | - format2.get(idx).unwrap().clone(), |
108 | | - format3.get(idx).unwrap().clone(), |
109 | | - ])); |
110 | | - }) |
| 117 | + black_box( |
| 118 | + to_timestamp() |
| 119 | + .invoke(&args.clone()) |
| 120 | + .expect("to_timestamp should work on valid values"), |
| 121 | + ) |
111 | 122 | }) |
112 | 123 | }); |
113 | 124 | } |
|
0 commit comments