Skip to content

Commit 08ac212

Browse files
committed
some improve
1 parent 2fed4a7 commit 08ac212

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

pyfastutil/native/annotations.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,28 @@
77

88

99
def native(func: __T) -> __T:
10+
"""
11+
A decorator that attempts to optimize a Python function by
12+
translating it into a native implementation.
13+
14+
**Note**: This decorator is an experimental prototype and has been
15+
abandoned. It is incomplete, lacks proper maintenance, and may not
16+
work as expected in all cases. Use it at your own risk.
17+
18+
Parameters:
19+
func (__T): The Python function to be optimized.
20+
21+
Returns:
22+
__T: The (potentially) optimized function.
23+
24+
Warning:
25+
This decorator has been deprecated and is no longer maintained.
26+
It is provided for demonstration purposes only and should not
27+
be used in production code.
28+
29+
Example:
30+
@native
31+
def add(a, b):
32+
return a + b
33+
"""
1034
return _native(func)

tests/benchmark/benchmark_Native2.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def native(n):
2828
return x
2929

3030

31-
def setupAsm():
31+
def setupRealNative():
3232
global asmFunc
3333

3434
asmCode = f"""
@@ -56,13 +56,25 @@ def realNative():
5656
return unsafe.callLongLong(asmFunc)
5757

5858

59+
60+
61+
62+
63+
64+
65+
66+
67+
68+
69+
70+
5971
def main():
6072
global SIZE
6173
print(f"---Python & Native & Real-Native for Benchmark---")
6274
print(f"Batch size: {SIZE}")
6375
print(f"Repeat: {REPEAT}\n")
6476

65-
setupAsm()
77+
setupRealNative()
6678
assert python(SIZE) == native(SIZE) == realNative()
6779
assert native.__doc__ == "<native method>"
6880

0 commit comments

Comments
 (0)