Skip to content

Commit f581b33

Browse files
committed
feat: Measure request generation time in pyarrow sample
1 parent b510cec commit f581b33

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

packages/google-cloud-bigquery-storage/samples/pyarrow/append_rows_with_arrow.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# limitations under the License.
1616
import datetime
1717
import decimal
18+
import time
1819

1920
from google.cloud import bigquery
2021
from google.cloud.bigquery import enums
@@ -178,6 +179,8 @@ def _create_request(batches):
178179

179180
batches_in_request = []
180181
current_size = 0
182+
total_time = 0
183+
request_count = 0
181184

182185
# Split table into batches with one row.
183186
for row_batch in pyarrow_table.to_batches(max_chunksize=1):
@@ -195,7 +198,13 @@ def _create_request(batches):
195198

196199
if current_size + batch_size > max_request_bytes and batches_in_request:
197200
# Combine collected batches and yield request
201+
request_count += 1
202+
start_time = time.time()
198203
yield _create_request(batches_in_request)
204+
end_time = time.time()
205+
request_time = end_time - start_time
206+
print(f"Time to generate request {request_count}: {request_time:.4f} seconds")
207+
total_time += request_time
199208

200209
# Reset for next request.
201210
batches_in_request = []
@@ -206,7 +215,15 @@ def _create_request(batches):
206215

207216
# Yield any remaining batches
208217
if batches_in_request:
218+
request_count += 1
219+
start_time = time.time()
209220
yield _create_request(batches_in_request)
221+
end_time = time.time()
222+
request_time = end_time - start_time
223+
print(f"Time to generate request {request_count}: {request_time:.4f} seconds")
224+
total_time += request_time
225+
226+
print(f"\nTotal time to generate all {request_count} requests: {total_time:.4f} seconds")
210227

211228

212229
def verify_result(client, table, futures):

0 commit comments

Comments
 (0)