Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit fa00839

Browse files
committed
Use monotonic instead of time
1 parent b5ba486 commit fa00839

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

data_diff/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def _main(
189189
for db in dbs:
190190
db.enable_interactive()
191191

192-
start = time.time()
192+
start = time.monotonic()
193193

194194
try:
195195
options = dict(
@@ -281,7 +281,7 @@ def _main(
281281

282282
sys.stdout.flush()
283283

284-
end = time.time()
284+
end = time.monotonic()
285285

286286
logging.info(f"Duration: {end-start:.2f} seconds.")
287287

data_diff/diff_tables.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,11 @@ def count(self) -> Tuple[int, int]:
225225

226226
def count_and_checksum(self) -> Tuple[int, int]:
227227
"""Count and checksum the rows in the segment, in one pass."""
228-
start = time.time()
228+
start = time.monotonic()
229229
count, checksum = self.database.query(
230230
self._make_select(columns=[Count(), Checksum(self._relevant_columns_repr)]), tuple
231231
)
232-
duration = time.time() - start
232+
duration = time.monotonic() - start
233233
if duration > RECOMMENDED_CHECKSUM_DURATION:
234234
logger.warning(
235235
f"Checksum is taking longer than expected ({duration:.2f}s). "
@@ -336,7 +336,7 @@ def diff_tables(self, table1: TableSegment, table2: TableSegment) -> DiffResult:
336336
send_event_json(event_json)
337337

338338
self.stats["diff_count"] = 0
339-
start = time.time()
339+
start = time.monotonic()
340340
try:
341341

342342
# Query and validate schema
@@ -384,7 +384,7 @@ def diff_tables(self, table1: TableSegment, table2: TableSegment) -> DiffResult:
384384
error = e
385385
finally:
386386
if is_tracking_enabled():
387-
runtime = time.time() - start
387+
runtime = time.monotonic() - start
388388
table1_count = self.stats.get("table1_count")
389389
table2_count = self.stats.get("table2_count")
390390
diff_count = self.stats.get("diff_count")

tests/test_database_types.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ def tearDown(self) -> None:
527527

528528
@parameterized.expand(type_pairs, name_func=expand_params)
529529
def test_types(self, source_db, target_db, source_type, target_type, type_category):
530-
start = time.time()
530+
start = time.monotonic()
531531

532532
self.src_conn = src_conn = CONNS[source_db]
533533
self.dst_conn = dst_conn = CONNS[target_db]
@@ -550,12 +550,12 @@ def test_types(self, source_db, target_db, source_type, target_type, type_catego
550550
self.src_table = src_table = ".".join(map(src_conn.quote, src_table_path))
551551
self.dst_table = dst_table = ".".join(map(dst_conn.quote, dst_table_path))
552552

553-
start = time.time()
553+
start = time.monotonic()
554554
if not BENCHMARK:
555555
_drop_table_if_exists(src_conn, src_table)
556556
_create_table_with_indexes(src_conn, src_table, source_type)
557557
_insert_to_table(src_conn, src_table, enumerate(sample_values, 1), source_type)
558-
insertion_source_duration = time.time() - start
558+
insertion_source_duration = time.monotonic() - start
559559

560560
values_in_source = PaginatedTable(src_table, src_conn)
561561
if source_db is db.Presto or source_db is db.Trino:
@@ -564,12 +564,12 @@ def test_types(self, source_db, target_db, source_type, target_type, type_catego
564564
elif source_type.startswith("timestamp"):
565565
values_in_source = ((a, datetime.fromisoformat(b.rstrip(" UTC"))) for a, b in values_in_source)
566566

567-
start = time.time()
567+
start = time.monotonic()
568568
if not BENCHMARK:
569569
_drop_table_if_exists(dst_conn, dst_table)
570570
_create_table_with_indexes(dst_conn, dst_table, target_type)
571571
_insert_to_table(dst_conn, dst_table, values_in_source, target_type)
572-
insertion_target_duration = time.time() - start
572+
insertion_target_duration = time.monotonic() - start
573573

574574
if type_category == "uuid":
575575
self.table = TableSegment(self.src_conn, src_table_path, "col", None, ("id",), case_sensitive=False)
@@ -578,13 +578,13 @@ def test_types(self, source_db, target_db, source_type, target_type, type_catego
578578
self.table = TableSegment(self.src_conn, src_table_path, "id", None, ("col",), case_sensitive=False)
579579
self.table2 = TableSegment(self.dst_conn, dst_table_path, "id", None, ("col",), case_sensitive=False)
580580

581-
start = time.time()
581+
start = time.monotonic()
582582
self.assertEqual(N_SAMPLES, self.table.count())
583-
count_source_duration = time.time() - start
583+
count_source_duration = time.monotonic() - start
584584

585-
start = time.time()
585+
start = time.monotonic()
586586
self.assertEqual(N_SAMPLES, self.table2.count())
587-
count_target_duration = time.time() - start
587+
count_target_duration = time.monotonic() - start
588588

589589
# When testing, we configure these to their lowest possible values for
590590
# the DEFAULT_N_SAMPLES.
@@ -598,9 +598,9 @@ def test_types(self, source_db, target_db, source_type, target_type, type_catego
598598
bisection_factor=ch_factor,
599599
max_threadpool_size=ch_threads,
600600
)
601-
start = time.time()
601+
start = time.monotonic()
602602
diff = list(differ.diff_tables(self.table, self.table2))
603-
checksum_duration = time.time() - start
603+
checksum_duration = time.monotonic() - start
604604
expected = []
605605
self.assertEqual(expected, diff)
606606
self.assertEqual(0, differ.stats.get("rows_downloaded", 0))
@@ -617,9 +617,9 @@ def test_types(self, source_db, target_db, source_type, target_type, type_catego
617617
differ = TableDiffer(
618618
bisection_threshold=dl_threshold, bisection_factor=dl_factor, max_threadpool_size=dl_threads
619619
)
620-
start = time.time()
620+
start = time.monotonic()
621621
diff = list(differ.diff_tables(self.table, self.table2))
622-
download_duration = time.time() - start
622+
download_duration = time.monotonic() - start
623623
expected = []
624624
self.assertEqual(expected, diff)
625625
self.assertEqual(len(sample_values), differ.stats.get("rows_downloaded", 0))

0 commit comments

Comments
 (0)