-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.py
68 lines (42 loc) · 1.46 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from __future__ import annotations
from typing import Any, TypeVar
from flywheel.fn.endpoint import FnCollectEndpoint, wrap_endpoint
from flywheel.globals import global_collect
from flywheel.overloads import SimpleOverload, TypeOverload
T = TypeVar("T")
class test:
type = TypeOverload("type")
sim = SimpleOverload("sim")
def call(self, value: type[T]) -> T:
for selection in self.collect.select():
if not selection.harvest(self.sim, value):
continue
selection.complete()
return selection(value)
@wrap_endpoint
@classmethod
def collect(cls, type: type[T]):
yield cls.sim.hold(type)
def shape(value: type[T]) -> T: ...
return shape
# @global_collect
# @test.implements(type=str)
def test_impl_str(value: type[str]):
return "11"
def t(value: type[Any]) -> Any: ...
global_collect(test.collect(type=str)(test_impl_str))
@global_collect
@test.collect(type=int)
def test_impl_int(value: type[int]):
return 11
# reveal_type(test)
import timeit
from viztracer import VizTracer
tracer = VizTracer()
tracer.start()
num = 3000
delta_a = timeit.timeit("test_impl_str('11')", globals=globals(), number=num)
delta_b = timeit.timeit("test().call(str)", globals=globals(), number=num)
print(f"test_impl_int: {delta_a}, call: {delta_b}, {delta_b/delta_a}, {num/delta_a}o/s, {num/delta_b}o/s")
tracer.stop()
tracer.save() # also takes output_file as an optional argument