Skip to content

Commit fa874d6

Browse files
committed
add separators in fannkuch + average out the runtime
1 parent 1043b43 commit fa874d6

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

Benchmark/fannkuch/advanced/main.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,25 @@
1313

1414
DEFAULT_ARG = 9
1515

16+
### SECTION SEPARATOR ###
1617

1718
def fannkuch(nb: int) -> int:
1819
n: int64 = int64(nb)
19-
count: Array[int64] = Array[int64](nb)
20+
### SECTION SEPARATOR ###
21+
count: Array[int64] = Array[int64](n)
2022
max_flips: int64 = 0
2123
m: int64 = n - 1
2224
r: int64 = n
23-
perm1: Array[int64] = Array[int64](nb)
24-
perm: Array[int64] = Array[int64](nb)
25+
perm1: Array[int64] = Array[int64](n)
26+
perm: Array[int64] = Array[int64](n)
2527
i: int64 = 0
2628
while i < n:
2729
count[i] = i + 1
2830
perm1[i] = i
2931
perm[i] = i
3032
i += 1
31-
perm0: Array[int64] = Array[int64](nb)
33+
### SECTION SEPARATOR ###
34+
perm0: Array[int64] = Array[int64](n)
3235

3336
while 1:
3437
while r != 1:
@@ -72,6 +75,8 @@ def fannkuch(nb: int) -> int:
7275
return box(max_flips)
7376
return 0
7477

78+
### SECTION SEPARATOR ###
79+
7580
if __name__ == "__main__":
7681
num_iterations = 1
7782
if len(sys.argv) > 1:
@@ -81,9 +86,7 @@ def fannkuch(nb: int) -> int:
8186

8287
for _ in range(num_iterations):
8388
res = fannkuch(DEFAULT_ARG)
84-
89+
assert res == 30
8590
end_time = time.time()
8691
runtime = end_time - start_time
87-
print(runtime)
88-
89-
# assert res == 30
92+
print(runtime / num_iterations)

Benchmark/fannkuch/shallow/main.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,17 @@
1313

1414
DEFAULT_ARG = 9
1515

16+
### SECTION SEPARATOR ###
1617

1718
def fannkuch(n: int) -> int:
19+
### SECTION SEPARATOR ###
1820
count: List[int] = list(range(1, n + 1))
1921
max_flips: int = 0
2022
m: int = n - 1
2123
r: int = n
2224
perm1: List[int] = list(range(n))
2325
perm: List[int] = list(range(n))
26+
### SECTION SEPARATOR ###
2427
perm1_ins: Callable[[int, int], None] = perm1.insert
2528
perm1_pop: Callable[[int], int] = perm1.pop
2629

@@ -51,6 +54,8 @@ def fannkuch(n: int) -> int:
5154
return max_flips
5255
return 0
5356

57+
### SECTION SEPARATOR ###
58+
5459
if __name__ == "__main__":
5560
num_iterations = 1
5661
if len(sys.argv) > 1:
@@ -59,9 +64,7 @@ def fannkuch(n: int) -> int:
5964
start_time = time.time()
6065
for _ in range(num_iterations):
6166
res = fannkuch(DEFAULT_ARG)
62-
67+
assert res == 30
6368
end_time = time.time()
6469
runtime = end_time - start_time
65-
print(runtime)
66-
67-
# assert res == 30
70+
print(runtime / num_iterations)

Benchmark/fannkuch/untyped/main.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@
99

1010
DEFAULT_ARG = 9
1111

12+
### SECTION SEPARATOR ###
1213

1314
def fannkuch(n):
15+
### SECTION SEPARATOR ###
1416
count = list(range(1, n + 1))
1517
max_flips = 0
1618
m = n - 1
1719
r = n
1820
perm1 = list(range(n))
1921
perm = list(range(n))
22+
### SECTION SEPARATOR ###
2023
perm1_ins = perm1.insert
2124
perm1_pop = perm1.pop
2225

@@ -47,6 +50,7 @@ def fannkuch(n):
4750
return max_flips
4851
return 0
4952

53+
### SECTION SEPARATOR ###
5054

5155
if __name__ == "__main__":
5256
import sys
@@ -61,4 +65,4 @@ def fannkuch(n):
6165
assert res == 30
6266
end_time = time.time()
6367
runtime = end_time - start_time
64-
print(runtime)
68+
print(runtime / num_iterations)

0 commit comments

Comments
 (0)