Skip to content

Commit 81b8991

Browse files
generatedunixname89002005287564facebook-github-bot
generatedunixname89002005287564
authored andcommittedOct 7, 2024·
ft_utils
Reviewed By: jermenkoo Differential Revision: D63884573 fbshipit-source-id: dae670155fc426f7b088b09747d08f885dd1f717
1 parent 9fd8480 commit 81b8991

11 files changed

+20
-19
lines changed
 

‎atomic_bench.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313
class LockedReference:
14-
def __init__(self, value: Optional[Any]) -> None: # pyre-ignore[2]
14+
def __init__(self, value: Any | None) -> None: # pyre-ignore[2]
1515
self._value = value
1616
self._lock = threading.Lock()
1717

‎benchmark_utils.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
import threading
1111
import time
1212
import traceback
13+
from collections.abc import Callable, Sequence
1314

14-
from typing import Callable, List, Sequence, Type, TypeVar
15+
from typing import List, Type, TypeVar
1516

1617
from ft_utils.local import BatchExecutor
1718

@@ -90,17 +91,17 @@ def benchmark_operation(operation_func: Callable[[], None]) -> float:
9091
def worker(
9192
operation_func: Callable[[], None],
9293
barrier: threading.Barrier,
93-
) -> List[float]:
94+
) -> list[float]:
9495
"""
9596
Executes the benchmark multiple times and collects run times.
9697
"""
9798
barrier.wait() # Synchronize the start of operations
98-
run_times: List[float] = [benchmark_operation(operation_func) for _ in range(5)]
99+
run_times: list[float] = [benchmark_operation(operation_func) for _ in range(5)]
99100
return run_times
100101

101102

102103
def execute_benchmarks(
103-
provider_class: Type[BenchmarkProvider],
104+
provider_class: type[BenchmarkProvider],
104105
) -> None:
105106
"""
106107
Sets up and executes benchmarks across multiple threads using methods from a BenchmarkProvider.

‎concurrent.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
# pyre-strict
44

55
import threading
6-
from typing import Any, Iterator, Optional
6+
from collections.abc import Iterator
7+
from typing import Any, Optional
78

89
from ft_utils._concurrent import AtomicInt64, AtomicReference, ConcurrentDict
910

@@ -38,7 +39,7 @@ class ConcurrentGatheringIterator:
3839
scaling (Optional(int)): expected number of threads or cores accessing the structure.
3940
"""
4041

41-
def __init__(self, scaling: Optional[int] = None) -> None:
42+
def __init__(self, scaling: int | None = None) -> None:
4243
if scaling is not None:
4344
self._dict: ConcurrentDict = ConcurrentDict(scaling)
4445
else:
@@ -107,7 +108,7 @@ def iterator_local(self, max_key: int, clear: bool = True) -> Iterator[Any]: #
107108

108109

109110
class ConcurrentQueue:
110-
def __init__(self, scaling: Optional[int] = None) -> None:
111+
def __init__(self, scaling: int | None = None) -> None:
111112
if scaling is not None:
112113
self._dict: ConcurrentDict = ConcurrentDict(scaling)
113114
else:

‎concurrent_dict_bench.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
class ConcurretDictBenchmarkProvider(BenchmarkProvider):
1616
def __init__(self, operations: int) -> None:
1717
self._operations = operations
18-
self._cdct: Optional[ConcurrentDict] = None
19-
self._dct: Optional[dict[int | str, int]] = None
18+
self._cdct: ConcurrentDict | None = None
19+
self._dct: dict[int | str, int] | None = None
2020

2121
def set_up(self) -> None:
2222
self._cdct = ConcurrentDict(os.cpu_count())

‎examples/consistent_counter.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
import threading
7-
from typing import Callable
7+
from collections.abc import Callable
88

99
from ft_utils.concurrent import AtomicInt64
1010
from ft_utils.synchronization import IntervalLock

‎examples/fibonacci.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def compute(): # pyre-ignore
5151
f.result()
5252

5353

54-
def fib_worker(n: int, memo: Dict[int, Tuple[int, int]]) -> Tuple[int, int]:
54+
def fib_worker(n: int, memo: dict[int, tuple[int, int]]) -> tuple[int, int]:
5555
# Check memoization cache in a thread-safe manner
5656
if n in memo:
5757
cached.incr()

‎lock_bench.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# pyre-strict
44

55
import threading
6-
from typing import Callable
6+
from collections.abc import Callable
77

88
from ft_utils.benchmark_utils import BenchmarkProvider, execute_benchmarks
99
from ft_utils.local import LocalWrapper

‎lock_test_utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import threading
88
import time
99
import unittest
10-
from typing import Callable
10+
from collections.abc import Callable
1111

1212
from ft_utils.concurrent import AtomicFlag, AtomicReference
1313

‎random_bench.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import random
66
import threading
7-
from typing import Callable
7+
from collections.abc import Callable
88

99
from ft_utils.benchmark_utils import BenchmarkProvider, execute_benchmarks
1010
from ft_utils.local import BatchExecutor, LocalWrapper

‎test_run_all.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ def run_test(filename):
1313
if f_tail != ".py":
1414
raise ValueError(f"filename `{filename}` is not a Python (.py) file")
1515
module = f"ft_utils.tests.{f_head}"
16-
result = subprocess.run(
17-
["python", "-m", module], stdout=subprocess.PIPE, stderr=subprocess.PIPE
18-
)
16+
result = subprocess.run(["python", "-m", module], capture_output=True)
1917
if result.returncode != 0:
2018
print(f"{module} failed:")
2119
print(result.stdout.decode())

‎tsp_bench.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
import sys
66
import threading
77
import time
8+
from collections.abc import Callable
89
from concurrent.futures import Future, ThreadPoolExecutor
9-
from typing import Any, Callable
10+
from typing import Any
1011

1112
# pyre-strict
1213

0 commit comments

Comments
 (0)
Please sign in to comment.