-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
catanatron_experimental/catanatron_experimental/benchmarks/benchmark_edge_id.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import timeit | ||
|
||
|
||
result = timeit.timeit("tuple(sorted((a,b)))", setup="a = 20; b = 45", number=2_000_000) | ||
print("TODAY", result) | ||
|
||
result = timeit.timeit( | ||
"(a,b) if a < b else (b,a)", setup="a = 20; b = 45", number=2_000_000 | ||
) | ||
print("TERNARY", result) | ||
|
||
result = timeit.timeit( | ||
"edge_id((a, b))", | ||
setup="a = 20; b = 45; edge_id = lambda x: (x[0],x[1]) if x[0] < x[1] else (x[1],x[0])", | ||
number=2_000_000, | ||
) | ||
print("FUNC TERNARY", result) | ||
|
||
result = timeit.timeit( | ||
"edge_id(a, b)", | ||
setup="a = 20; b = 45; edge_id = lambda x, y: (x,y) if x < y else (y,x)", | ||
number=2_000_000, | ||
) | ||
print("FUNC TERNARY 2 PARAMS", result) | ||
|
||
result = timeit.timeit( | ||
"(min(a, b), max(a, b))", setup="a = 20; b = 45", number=2_000_000 | ||
) | ||
print("MIN MAX", result) | ||
|
||
# I like map lookup because makes it easy to change to INT ids in the future (a more | ||
# compact representation of an edge) | ||
result = timeit.timeit( | ||
"edge_id[(a,b)]", setup="a = 20; b = 45; edge_id = {(a,b): 1}", number=2_000_000 | ||
) | ||
print("MAP LOOKUP", result) |